class Watcher: _app_ids = ['com.kuaishou.nebula', # 快手 'com.ss.android.ugc.aweme.lite', # 抖音 'com.jm.video', # 刷宝 'com.yuncheapp.android.pearl', # 快点看 ] def __init__(self, d): self._operator = Operator(d) self._reader = Reader(d) self._d = d def watch(self): i = 0 while True: try: package_name = self._d.app_current()['package'] except Exception as e: print('Get package name failed', e) package_name = None if package_name is None or package_name not in self._app_ids: print(package_name) sleep_random(1, 7) continue print(i, '-', get_local_time()) self._reader.page_up() sleep_random(5, 15) i += 1
def wrapper(*args, **kwargs): from util.reader import Reader reader = Reader() if reader.is_login(): wrapper.__name__ = func.__name__ # 这里注意为什么要改名字, 因为如果还是执行原函数, 记日志的时候要记原来的操作名 res = func(*args, **kwargs) return res else: wrapper.__name__ = 'login_passively' res = reader.login() return res
def __init__(self, d): self._d = d self._operator = Operator(d) self._reader = Reader(d) self._article_list_res = 'com.jifen.qukan:id/aly' self._top_left_bonus_res = 'com.jifen.qukan:id/bwg' self._top_left_bonus_text = '领取' self._comment_res = 'com.jifen.qukan:id/a0o' self._comment_text = '全部评论'
def wrapper(*args, **kwargs): # 如果reader和common存在相互引用, import不能放在上面 # 当然, 最好的方式是不要有相互引用, 不要直接在reader里@log, @auth from util.reader import Reader res = func(*args, **kwargs) now = time.strftime('%Y-%m-%d %X') # 记录内容为时间, 用户名, 操作名, 返回值 data = "{}|{}|{}|{}\n".format(now, Reader().get_user(), func.__name__, res) with open(settings.LOG_PATH, 'a', encoding='utf-8') as f: f.write(data) return res
class TaoXiaoShuo: _app_id = 'com.martian.ttbook' _article_list_res = 'com.martian.ttbook:id/bs_list_book_name' _article_read_res = 'com.martian.ttbook:id/bd_reading' _article_advertise_close_res = 'com.martian.ttbook:id/bt_cancel' _article_save_to_shell_res = 'com.martian.ttbook:id/dialog_close' _article_end_res = 'com.martian.ttbook:id/tv_buy_reading_purcgase' _article_end_text = '余额不足请充值' def __init__(self, device_id): self._d = u2.connect_usb(device_id) self._operator = Operator(self._d) self._reader = Reader(self._d) def get_article_list_length(self): return self._operator.get_resource_length(self._article_list_res) def next_article_list(self): self._reader.page_up() time.sleep(3) def in_article(self, i): self._reader.in_article(self._article_list_res, i) time.sleep(3) self._operator.click_resource_if_exist(self._article_read_res) time.sleep(3) self._operator.click_resource_if_exist(self._article_advertise_close_res) def out_article(self): print(self._operator.get_resource_text('com.martian.ttbook:id/duration_bonus')) self._operator.go_back() time.sleep(3) self._operator.click_resource_if_exist(self._article_save_to_shell_res) time.sleep(3) while 0 == self.get_article_list_length(): self._operator.go_back() time.sleep(3) def check_end(self): text = self._operator.get_resource_text(self._article_end_res) return text is not None and text == self._article_end_text def read(self): i = 0 while not taoxiaoshuo.check_end(): i += 1 now = int(time.time()) time_struct = time.localtime(now) print(i, '-', time.strftime("%Y-%m-%d %H:%M:%S", time_struct)) self._reader.page_left() time.sleep(random.randint(5, 7)) self._operator.click_resource_if_exist(self._article_advertise_close_res)
def parse_features_collection_json(): # path_to_file = '/Users/akratovich/projects/python/python_stud/parser/real_json_sample.json' path_to_file = '/Users/akratovich/projects/python/sf-city-lots-json/citylots.json' parsed_features = [] features_collection = Reader.read_json(path_to_file) for feature_item in features_collection['features']: tmp_coord_list = __get_points(feature_item) tmp_figure_type = __get__geometry_type(feature_item) tmp_geometry = Geometry(tmp_figure_type, tmp_coord_list) tmp_feature_type = __get_feature_type(feature_item) tmp_prop_list = __get_prop_feature_prop_list(feature_item) feature = Feature(tmp_feature_type, tmp_prop_list, tmp_geometry) # print(feature.__str__()) parsed_features.append(feature) print('{0} features are parsed'.format(parsed_features.__len__())) print('Parsed {0} features'.format(parsed_features.__len__())) return parsed_features
def __init__(self, d): self._d = d self._operator = Operator(d) self._reader = Reader(d) self._bonus_res = 'com.ss.android.ugc.aweme.lite:id/kh'
class Shuabao(object): _app_id = 'com.jm.video' _resource_id = _app_id + ":id/" _res_my_name = _resource_id + 'tv_name' def __init__(self, d): self._d = d self._operator = Operator(d) self._reader = Reader(d) self._bonus_res = 'com.ss.android.ugc.aweme.lite:id/kh' def start_app(self): self._operator.close_all_app() self._operator.start_app(self._app_id) # 右下角“我” def right_bottom_me(self): print("Click 我") self._operator.into_page_xpath('//*[@text="我"]', self._res_my_name, None) def watch_adv(self): sleep(35) while not self._operator.is_resource_exists( 'com.jm.video:id/tt_video_ad_close'): sleep(1) self._operator.click_resource_if_exist( 'com.jm.video:id/tt_video_ad_close') # 提钱 def withdraw(self): if get_hour() < 12: return adv_finish = False while not adv_finish: if self._operator.is_xpath_exist('//*[@text="提现"]'): self._operator.click_xpath_if_exist('//*[@text="提现"]') if self._operator.is_xpath_exist('//*[@text="立即观看"]'): self._operator.click_xpath_if_exist('//*[@text="立即观看"]') self.watch_adv() self._operator.go_back() else: adv_finish = True if self._operator.is_xpath_exist('//*[@text="提现"]'): self._operator.click_xpath_if_exist('//*[@text="提现"]') if self._operator.is_xpath_exist('//*[@text="立即提现"]'): self._operator.click_xpath_if_exist('//*[@text="立即提现"]') self._operator.click_xpath_if_exist('//*[@text="赚更多元宝"]') def sign(self): self.right_bottom_me() # 中间任务 print("Click 任务") self._operator.click_xpath_if_exist('//*[@text="任务"]') if self._operator.is_resource_exists('com.jm.video:id/imgClose'): self._operator.click_resource_if_exist('com.jm.video:id/imgClose') self.withdraw() if self._operator.is_xpath_exist('//*[@text="立即签到"]'): self._operator.click_xpath_if_exist('//*[@text="立即签到"]') if self._operator.is_xpath_exist('//*[@text="放弃签到看视频签到"]'): resource = self._d.xpath('//*[@text="放弃签到看视频签到"]') resource.click() self.watch_adv() self._operator.click_xpath_if_exist( '//*[@text="刷宝短视频"]/android.view.View[1]/android.view.View[6]/android.view.View[1]/android.view.View[1]' ) def watch(self): i = 0 while i < 15: print(i, '-', get_local_time(), '-', self._operator.get_resource_text('com.jm.video:id/desc')) self._reader.page_up() sleep_random() i += 1 def is_video(self): return self._operator.is_xpath_exist( '//*[@resource-id="com.jm.video:id/tabLayout"]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]' ) def go_to_video(self): while not self.is_video(): self._operator.go_back() self._operator.click_xpath_if_exist( '//*[@resource-id="com.jm.video:id/tabLayout"]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]' ) def shuabao(self): print("%s Shuabao start ..." % get_local_time()) self.start_app() self.sign() self.go_to_video() self.watch() self._operator.close_all_app() print("%s Shuabao end ..." % get_local_time())
def __init__(self, d): self._d = d self._operator = Operator(d) self._reader = Reader(d)
class Kuaishou: _app_id = 'com.ss.android.ugc.aweme.lite' _resource_id = _app_id + ":id/" _res_my_name = _resource_id + 'rd' _btn_laizhuanqian = _resource_id + 'ke' # 下方中间钱包按钮 _btn_continue_adv = _resource_id + 'a_g' # 继续观看视频按钮 _xpath_watch = '//*[@resource-id="app"]/android.view.View[2]/android.view.View[3]' # 宝箱观看视频领更多金币 _res_video_desc = _resource_id + 'tt' def __init__(self, d): self._d = d self._operator = Operator(d) self._reader = Reader(d) def start_app(self): self._operator.close_all_app() # self._operator.start_app(self._app_id) # if self._operator.is_resource_exists('com.ss.android.ugc.aweme.lite:id/al3'): # self._operator.click_resource_if_exist('com.ss.android.ugc.aweme.lite:id/al3') # if self._operator.is_resource_exists('com.ss.android.ugc.aweme.lite:id/tc'): # self._operator.click_resource_if_exist('com.ss.android.ugc.aweme.lite:id/tc') # 右下角“我” def into_me(self): print("Into 我") return self._operator.into_page_xpath('//*[@text="我"]', self._btn_laizhuanqian, None) def into_zhuanqian(self): print("Into 赚钱") return self._operator.into_page_resource(self._btn_laizhuanqian, None, '//*[@text="金币收益"]') def into_video(self): i = 0 while not self._operator.is_resource_exists(self._res_video_desc): i += 1 if i > 10: return False self.into_me() self._operator.click_xpath_if_exist('//*[@text="首页"]') return True def task(self): if self._operator.is_xpath_exist('//*[@text="看视频再赚"]'): self._operator.click_xpath_if_exist('//*[@text="看视频再赚"]') self.watch_adv() self._operator.go_back() # if self._operator.is_xpath_exist('//*[@text="开宝箱得金币"]'): # self._operator.click_xpath_if_exist('//*[@text="开宝箱得金币"]') # if self._operator.is_xpath_exist(self._xpath_watch): # self._operator.click_xpath_if_exist(self._xpath_watch) # self.watch_adv() # 提钱 def withdraw(self): if get_hour() < 11: return if self._operator.is_xpath_exist('//*[@text="去提现"]'): self._operator.click_xpath_if_exist('//*[@text="去提现"]') if self._operator.is_xpath_exist('//*[@text="天天提"]'): self._operator.click_xpath_if_exist('//*[@text="天天提"]') self._operator.click_xpath_if_exist('//*[@text="立即提现"]') self._operator.click_xpath_if_exist( '//android.app.Dialog/android.view.View[1]/android.view.View[4]' ) def sign(self): if not self.into_me(): return False # 中间取钱 if not self.into_zhuanqian(): return False self.withdraw() self.task() if not self.into_me(): return False # self._operator.click_xpath_if_exist('//*[@resource-id="app"]/android.view.View[3]') # self.watch_adv() # 第二行整点广告领取金币 # if self._operator.is_xpath_exist('//*[@text="去领取"]'): # self._operator.click_xpath_if_exist('//*[@text="去领取"]') # self._operator.click_resource_if_exist('com.ss.android.ugc.aweme.lite:id/yv') return True def watch_advs(self): i = 0 while i < 20: self.watch_adv() i += 1 def watch_adv(self): while True: try: self._d.xpath('//*[@text="看视频赚海量金币"]').click() break except Exception as e: print('Click resource failed' + str(e)) count = 0 while not self._operator.is_resource_exists( 'com.ss.android.ugc.livelite:id/rk'): sleep(5) count += 1 if count > 8: self._operator.click_xpath_if_exist('//*[@text="关闭广告"]') return self._operator.click_resource_if_exist( 'com.ss.android.ugc.livelite:id/rk') def watch(self): i = 0 while i < 150: print(i, '-', get_local_time()) self._reader.page_up() sleep_random(20, 30) i += 1 def is_video(self): return self._operator.is_xpath_exist('//*[@text="首页"]') def douyin(self): print("%s Douyin start ..." % get_local_time()) # self.start_app() if not self.sign(): return if not self.into_video(): return self.watch() self._operator.close_all_app() print("%s Douyin end ..." % get_local_time())
# -*- coding: utf-8 -*- # Author: Cynthia """ 实现一个电子阅读器 数据库采用本地文件模拟 """ import sys import settings from util import common from util.book import Book from util.reader import Reader reader = Reader() # 注册 @common.log def register(): """ :return: """ while True: state = reader.register() if state: return state # 主动登陆 @common.log def login(): while True:
class QuTouTiao(object): _app_id = 'com.jifen.qukan' _resource_id = _app_id + ":id/" def __init__(self, d): self._d = d self._operator = Operator(d) self._reader = Reader(d) self._article_list_res = 'com.jifen.qukan:id/aly' self._top_left_bonus_res = 'com.jifen.qukan:id/bwg' self._top_left_bonus_text = '领取' self._comment_res = 'com.jifen.qukan:id/a0o' self._comment_text = '全部评论' def start_app(self): self._operator.close_all_app() self._operator.start_app(self._app_id) # 右下角“我” def into_me(self): print("Click 我的") while not self._operator.is_xpath_exist('//*[@text="查看个人主页"]'): self._operator.click_xpath_if_exist('//*[@text="我的"]') def sign(self): self.into_me() self.withdraw() print("Click 去签到") self._operator.click_xpath_if_exist('//*[@text="去签到"]') self._operator.click_xpath_if_exist('//*[@text="任务"]') i = 0 while not self._operator.is_xpath_exist('//*[@text="挑战60天超长签到"]'): print("60天超长签到") i += 1 if i > 10: break self._reader.page_up() self._operator.click_xpath_if_exist('//*[@text="挑战60天超长签到"]') self._operator.go_back() def current_position(self): if self._operator.is_resource_exists( 'com.jifen.qukan:id/nz') and self._operator.is_resource_exists( 'com.jifen.qukan:id/bpq'): return 'ARTICLE' else: return 'LIST' def withdraw(self): print("提现") # if get_hour() < 12: # return self._operator.click_xpath_if_exist('//*[@text="我的"]') self._operator.click_resource_if_exist('com.jifen.qukan:id/auv') self._operator.click_xpath_if_exist('//*[@text="提现"]') self._operator.click_resource_if_exist('alipay_quick') self._operator.click_xpath_if_exist('//*[@text="我知道了"]') self._operator.go_back() self._operator.go_back() self._operator.go_back() def read(self): print("阅读文章") self._operator.click_xpath_if_exist('//*[@text="我的"]') self._operator.click_xpath_if_exist('//*[@text="头条"]') self._operator.click_xpath_if_exist('//*[@text="刷新"]') total_artical = 0 while total_artical < 5: self._reader.page_up() article_list_length = self.get_article_list_length() self.get_top_left_bonus() for i in range(0, article_list_length): if self.in_article(i): self.read_article() total_artical += 1 self._operator.go_back() print("total_artical: ", total_artical) def watch(self): print("观看视频") self._operator.click_xpath_if_exist('//*[@text="我的"]') self._operator.click_xpath_if_exist('//*[@text="视频"]') self._operator.click_xpath_if_exist('//*[@text="刷新"]') total_video = 0 while total_video < 6: print("total_video: ", total_video) self._operator.click_resource_if_exist('com.jifen.qukan:id/qy') total_video += 1 self.get_money() if self._operator.is_resource_exists('com.jifen.qukan:id/ud'): text = self._operator.get_resource_text( 'com.jifen.qukan:id/ud') if text is not None and text == '继续观看': self._operator.click_resource_if_exist( 'com.jifen.qukan:id/ud') sleep_random() self._reader.page_up() def get_top_left_bonus(self): bonus_text = self._operator.get_resource_text(self._top_left_bonus_res) if bonus_text is not None and bonus_text == self._top_left_bonus_text: self._operator.click_resource_if_exist(self._top_left_bonus_res) def check_end(self): text = self._operator.get_resource_text(self._comment_res) return text is not None and text == self._comment_text def get_money(self): if self._operator.is_resource_exists('com.jifen.qukan:id/brl'): self._operator.click_resource_if_exist('com.jifen.qukan:id/brl') self._operator.click_resource_if_exist('com.jifen.qukan:id/a66') def get_article_list_length(self): length = self._reader.get_article_list_length(self._article_list_res) while length == 0: self._reader.page_up() length = self._reader.get_article_list_length( self._article_list_res) return length def in_article(self, i): if self._reader.in_article(self._article_list_res, i): sleep() return True else: return False def read_article(self): up_count = 0 while not self.check_end() and up_count < 10: self._reader.read_article('V') up_count += 1 self.get_money() def qutoutiao(self): print("%s Qutoutiao start ..." % get_local_time()) self.start_app() self.sign() self.read() self.watch() self._operator.close_all_app() print("%s Qutoutiao end ..." % get_local_time())
# -*- coding:utf-8 -*- from nltk.util import ngrams from util.kneser_ney import KneserNeyLM from util.reader import Reader import time train_seg = 'LM_data/train.seg' lm_arpa = 'train.arpa' reader = Reader() sents = reader.read_seg(train_seg) print('Read sentences done!') ngrams3 = (ngram for sent in sents for ngram in ngrams(sent, 3, pad_left=False, pad_right=False)) lm = KneserNeyLM(3) print('Start train...') start = time.time() lm.train(ngrams3) end = time.time() print('Train cost {:.2f}s'.format(end - start)) lm.save_lm(lm_arpa) print('Save trained lm to {:s}'.format(lm_arpa))
class MiDu: _app_id = 'com.lechuan.mdwz' _resource_id = _app_id + ":id/" _res_article_list = _resource_id + 'gm' _res_article_read = _resource_id + 're' _res_article_advertise_close = _resource_id + 'p6' _btn_adv_in_adv = _resource_id + 'pe' _btn_adv_close_adv = _resource_id + 'tt_video_ad_close' # _article_save_to_shell_res = 'com.martian.ttbook:id/dialog_close' # _article_end_res = 'com.martian.ttbook:id/tv_buy_reading_purcgase' # _article_end_text = '余额不足请充值' def __init__(self, d): self._d = d self._reader = Reader(d) self._operator = Operator(d) self._reader = Reader(d) def page_up(self): self._reader.page_up() def start_app(self): self._operator.close_all_app() self._operator.start_app(self._app_id) while not (self._operator.is_xpath_exist('//*[@text="我的"]') and self._operator.is_xpath_exist('//*[@text="福利"]')): self._operator.go_back() def into_me(self): print("Into 我") return self._operator.into_page_xpath('//*[@text="我的"]', None, None) def get_article_list_length(self): return self._operator.get_resource_length(self._article_list_res) def next_article_list(self): self.page_up() sleep() def in_article(self, i): self._reader.in_article(self._article_list_res, i) sleep() self._operator.click_resource_if_exist(self._article_read_res) sleep() self._operator.click_resource_if_exist( self._article_advertise_close_res) def out_article(self): print( self._operator.get_resource_text( 'com.martian.ttbook:id/duration_bonus')) self._operator.go_back() sleep() # self._operator.click_resource_if_exist(self._article_save_to_shell_res) # time.sleep(3) while 0 == self.get_article_list_length(): self._operator.go_back() sleep() def check_end(self): return False # text = self._operator.get_resource_text(self._article_end_res) # return text is not None and text == self._article_end_text def read(self): i = 0 while not self.check_end(): i += 1 print(i, '-', get_local_time()) try: self._d.click(0.988, round(random.uniform(0.3, 0.7), 3)) except Exception as e: print('Click resource failed' + str(e)) sleep_random(2, 5) self._operator.click_resource_if_exist('com.lechuan.mdwz:id/oh') # 看视频翻倍金币 # if self._operator.is_resource_exists(self._btn_adv_in_adv): # self._operator.click_resource_if_exist(self._btn_adv_in_adv) # while self._operator.is_resource_exists(self._btn_adv_close_adv): # sleep() # self._operator.click_resource_if_exist(self._btn_adv_close_adv) # self._operator.click_resource_if_exist(self._res_article_advertise_close) # self._operator.click_resource_if_exist('com.lechuan.mdwz:id/g_') # s = self._operator.get_resource_text('com.lechuan.mdwz:id/nz') # if s is not None and s == '立即领取': # self._operator.click_resource_if_exist('com.lechuan.mdwz:id/nz') # time.sleep(1) # self._operator.click_resource('com.lechuan.mdwz:id/g_') # self._operator.click_resource_if_exist('com.lechuan.mdwz:id/gy') def midu(self): self.start_app()
def __init__(self, device_id): self._d = u2.connect_usb(device_id) self._operator = Operator(self._d) self._reader = Reader(self._d)
# -*- coding:utf-8 -*- from util.reader import Reader from util.kneser_ney import KneserNeyLM import time reader = Reader() sents = reader.read_seg('LM_data/test.seg') print('Read sentences done!') lm = KneserNeyLM(3) start = time.time() lm.read_lm('train.arpa') end = time.time() print('Load lm done! Cost {:.2f}s'.format(end - start)) print('Test lm begin...') start = time.time() lm.test_pp(sents) end = time.time() print('Test end. Cost {:.2f}s'.format(end - start))