Exemplo n.º 1
0
def catch_fish():
    socket.setdefaulttimeout(None)
    def get_captcha():
        while True:
            try:
                req = urllib2.Request("http://xiaonei.paopaoyu.cn/getCaptcha/?nocache=%d.987654321" % \
                        int(time.time()*1000),
                        headers = {"Cookie": cookie, 
                                   "User-Agent": user_agent,
                                   "Referer": refer})
                break
            except:
                print u"获取验证码失败, 渔民杯具了"
                continue
        fname = tempfile.mktemp(".jpg")
        with open(fname, "wb") as fp:
            fp.write( urllib2.urlopen(req).read() )
        if config['auto-captcha']:
            return cal_captcha(fname) or get_captcha() # recur
        else:
            return ask_captcha(fname)
        #im = Image.open(fname)
        #im = im.filter(ImageFilter.ModeFilter()).filter(ImageFilter.MinFilter())
        #im.show()
        #return int(raw_input("You See:").strip()) 
    def parseJS(js, code):
        if len(code)== 1:
            code = code[0]              # 12.2 modified, useless maybe
        delim = re.findall(r"\d+", js)
        parms = map(int, delim)         # 11.30 modified
        if len(parms)== 2:
            a, b = map(int, delim)
            return str( code[a:b] )
        else:                            # before 11.30, now useless
            a, b, c, d = map(int, delim)        # fixed
            return str( code[a:b] + code[c:d] )

    # def catch_fish begins
    global res, anti_cheating
    max_level = minor_level if minor_level!= 0 else random.choice([1,3,5]) # a random seq
    for i in xrange(1, max_level+1): #
        catched = False
        lv = "%d%d" % (main_level, i)
        level = gameService.catchFishStartLevelAMF(uid, lv, main_level) if i== 1 \
                else gameService.catchFishStartLevelAMF(uid, lv)
        # print level
        if level.get('fish', []):
            print u"此次可抓到:", fish_str( level['fish']['style'] )
            catched = True
            fstr = level['fish']['style']
            if minor_level== 5 and config["auto-filter"]:
                if 'nn' in fstr or 'll' in fstr or 'adl' in fstr or 'z' in fstr or 'fh' in fstr:
                    catched = True
                else:
                    catched = False
                    if i== 5:
                        print u"没好鱼, 杯具不抓了"
                        return
                    else:
                        print u"烂鱼! 跳过"
        socket.setdefaulttimeout(10)    # set
        wait(42+ i*anti_cheating + main_level*7, u"第%d关 ".encode(CODEC) % i)
        socket.setdefaulttimeout(None)  # release
        js = gameService.catchFishCompleteLevelAMF(uid, lv, catched) # odd level you'll get fish
        # print js
        if not js.get('js_script', False):
            print u"出错", js
            if js.get('error','asdf')== u'are you cheating?':
                print u"尝试修改时间参数,重试中..."
                anti_cheating+= 6
                time.sleep(10)
                js = gameService.catchFishCompleteLevelAMF(uid, lv, catched) # try again
                if 'js_script' not in js:
                    return
            else:
                return
        varify_code = level['varify_code']
        code = parseJS(js['js_script'], varify_code)
    for _ in xrange(3):
        captcha_code = int(get_captcha()) # int() is needless
        res = gameService.catchFishGiveUpLevelAMF(uid, lv, code, captcha_code)
        if res and res.get('success', None): # bug here, banned?
            print u"成功捉鱼"
            break
        else:
            print u"失败", res
    req_fail(pubseaService, "getPubSeaInfoAMF", uid)
    socket.setdefaulttimeout(10)
Exemplo n.º 2
0
    print u"%s(%s星)" % (r.get('name', "????"), r.get('star', '?')),

print u"= 塑料袋 ="
types = [2, 3, 5, 7, 11, 13, 1]
all_fishes = []
for t in types:
    print u"== %s ==" % family_dict.get(t, str(t))
    fishes = []                         #                 family, type, is_change_family, page
    res = req_safe(productsService, "getMyBagObjectListAMF", uid, t, u'f', True) # 11.30 modified
    # print res
    if res: # some maybe None
        print u"共%d条" % res['total_num']
        fishes.extend( res['objList'] )
        all_fishes.extend( fishes )
        for f in fishes:
            print fish_str(f['style']),
            if (config["delete-fish"] and worth_delete(f)):
                print u"[卖鱼",
                res = req_safe(productsService, "deleteObjectAMF", uid, f['id'], u'f')
                if res.get('get_food', 0):
                    print u'%d鱼食]' % res['get_food'] ,
            if config["decompose-fish"] and worth_decompose(f):
                print u"[Decompose]",
                res = req_safe(syntheticService, "decomposeFishAMF", uid, f['id'])
                print_decompose_result(res)
    print

# TODO: some function definition
# TODO: Refactor using OOP

# 好友杯具部分 ########################################