MyMiniCity用クライアント

実行には Python2.3以上で,mechanize が必須です.

以下のコードをファイルに保存して,myminicityという名前で保存.

もし http://ura5han.myminicity.com/ という名前ならば

> python2.3 myminicity ura5han

http://ura5han.myminicity.com/ind ならば

> python2.3 myminicity ura5han ind

と実行してください.(上記2つはPythonバージョンが2.3の場合.indの部分はtraやsecに置き換えられます.)

実行時のリスクは自己責任で宜しくお願いします.

   1 #!/usr/bin/env python
   2 
   3 import mechanize
   4 import time
   5 import logging
   6 import sys
   7 
   8 def usage(msg=""):
   9     print >>sys.stderr, 'usage: %s cityname [path]' % sys.argv[0]
  10     sys.exit(1)
  11 
  12 path = ''
  13 if len(sys.argv) == 2:
  14     cityname = sys.argv[1]
  15 elif len(sys.argv) == 3:
  16     cityname = sys.argv[1]
  17     path = sys.argv[2]
  18 else:
  19     usage()
  20 
  21 #time.sleep(random.randint(1,1000))
  22 UA = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET)'
  23 HOST = '%s.myminicity.com' % sys.argv[1]
  24 BASEURL = 'http://%s/' % HOST
  25 DATAHOST = 'data.myminicity.com'
  26 BASEURL_DATA = 'http://%s/' % DATAHOST
  27 
  28 MAINFILES = '''\
  29 %s
  30 
  31 js/app.js?v=0'''
  32 
  33 FILES = '''\
  34 css/style.css?v=0
  35 js/swfobject.js?v=0
  36 img/flags/fr.gif
  37 swf/name.swf?v=0
  38 swf/client.swf?v=0
  39 img/ads/naturalchimie_en.gif
  40 img/xml-button.png
  41 img/rss-button.png
  42 swf/countries.en.txt
  43 img/icons/newind.gif
  44 img/icons/birth.gif
  45 img/icons/tra.gif
  46 img/header.gif
  47 img/largeBtn.gif
  48 img/sep.gif
  49 img/slot_link.gif
  50 img/slotGreen.gif
  51 img/boxInfo.gif
  52 img/statsbg.gif'''.split('\n')
  53 
  54 bot = mechanize.Browser()
  55 cookiejar = mechanize.CookieJar()
  56 bot.set_cookiejar(cookiejar)
  57 logger = logging.getLogger("mechanize")
  58 logger.addHandler(logging.StreamHandler(sys.stdout))
  59 logger.setLevel(logging.INFO)
  60 
  61 bot.set_debug_http(False)
  62 bot.set_debug_redirects(False)
  63 bot.set_debug_responses(False)
  64 
  65 bot.addheaders = [
  66     ('User-agent', UA),
  67     ('Host', HOST),
  68     ]
  69 
  70 # first contact
  71 bot.open(BASEURL + path)
  72 bot.response().read()
  73 
  74 # prepare second contact
  75 bot.addheaders.append(('Cookie', 'X-MV-Referer=; X-Ref-Ok=1'))
  76 
  77 for url in [(BASEURL + f) for f in (MAINFILES % path).split('\n')]:
  78     bot.open(url)
  79     bot.response().read()
  80 
  81 bot.addheaders = [
  82     ('User-agent', UA),
  83     ('Host', DATAHOST),
  84     ('Referer', BASEURL),
  85     ]
  86 
  87 for url in [(BASEURL_DATA + f) for f in FILES]:
  88     bot.open(url)
  89     bot.response().read()

Python/MyMiniCity (last edited 2008-01-15 09:52:37 by KeisukeUrago)