Skip to content

Commit

Permalink
normal task
Browse files Browse the repository at this point in the history
  • Loading branch information
yjqiang committed Aug 1, 2018
1 parent de4ee40 commit 1a676d6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 32 deletions.
35 changes: 17 additions & 18 deletions task.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,35 +134,35 @@ async def handle_1_roomid_raffle(self, i):

class Task(Messenger):

async def init(self):
self.call_after('sliver2coin', 0)
self.call_after('doublegain_coin2silver', 0)
self.call_after('DoSign', 0)
self.call_after('Daily_bag', 0)
self.call_after('Daily_Task', 0)
self.call_after('link_sign', 0)
# self.call_after('send_gift', 0)
#self.call_after('auto_send_gift', 0)
self.call_after('BiliMainTask', 0)
self.call_after('judge', 0)
self.call_after('open_silver_box', 0)
def init(self):
self.call_after('daily_task', 0, ('sliver2coin',), time_range=25)
self.call_after('daily_task', 0, ('doublegain_coin2silver',), time_range=25)
self.call_after('daily_task', 0, ('DoSign',), time_range=25)
self.call_after('daily_task', 0, ('Daily_bag',), time_range=25)
self.call_after('daily_task', 0, ('Daily_Task',), time_range=25)
self.call_after('daily_task', 0, ('link_sign',), time_range=25)
# self.call_after('daily_task', 0, ('send_gift',), time_range=25)
#self.call_after('daily_task', 0, ('auto_send_gift',), time_range=25)
self.call_after('daily_task', 0, ('BiliMainTask',), time_range=25)
self.call_after('daily_task', 0, ('judge',), time_range=25)
self.call_after('daily_task', 0, ('open_silver_box',), time_range=25)

async def run(self):
#await self.init()
self.init()
while True:
i = await self.queue.get()
print(i, '一级')
# await self.notify(*i)
await self.raffle_notify(*i)

def call_after(self, func, delay, id=None, time_range=None):
def call_after(self, func, delay, tuple_values, id=None, time_range=None):
if time_range is None:
value = (func, (), id)
value = (func, tuple_values, id)
self.loop.call_later(delay, self.queue.put_nowait, value)
print(value)
else:
for id, add_time in self.set_delay_times(time_range):
value = (func, (), id)
value = (func, tuple_values, id)
self.loop.call_later(delay + add_time, self.queue.put_nowait, value)

return
Expand All @@ -174,8 +174,7 @@ def call_at(self, func, time_expected, tuple_values, id=None, time_range=None):
value = (func, tuple_values, id)
self.loop.call_later(delay, self.queue.put_nowait, value)
print(value)
else:
print(time_range, 'hhhhhjjjkkkkkkkkk')
else:
for id, add_time in self.set_delay_times(time_range):
value = (func, tuple_values, id)
print('分布时间', value, id, add_time)
Expand Down
46 changes: 32 additions & 14 deletions user.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ async def open_silver_box(self):
json_rsp = await self.webhub.get_silver(time_start, time_end)
if json_rsp is None or json_rsp['code'] == -10017 or json_rsp['code'] == -800:
sleeptime = (utils.seconds_until_tomorrow() + 300)
Task().call_after('open_silver_box', sleeptime, self.user_id)
# Task().call_after('open_silver_box', sleeptime, self.user_id)
return sleeptime
break
# await asyncio.sleep(sleeptime)
elif not json_rsp['code']:
Expand All @@ -168,7 +169,8 @@ async def open_silver_box(self):
except :
sleeptime = 180
print(json_rsp)
Task().call_after('open_silver_box', sleeptime, self.user_id)
# Task().call_after('open_silver_box', sleeptime, self.user_id)
return sleeptime
break

async def handle_1_substantial_raffle(self, i, g):
Expand Down Expand Up @@ -635,7 +637,8 @@ async def Daily_bag(self):
# no done code
for i in json_response['data']['bag_list']:
self.printer_with_id(["# 获得-" + i['bag_name'] + "-成功"])
Task().call_after('Daily_bag', 21600)
# Task().call_after('Daily_bag', 21600)
return 21600


# 签到功能
Expand All @@ -647,7 +650,8 @@ async def DoSign(self):
sleeptime = (utils.seconds_until_tomorrow() + 300)
else:
sleeptime = 350
Task().call_after('DoSign', sleeptime, self.user_id)
# Task().call_after('DoSign', sleeptime, self.user_id)
return sleeptime

# 领取每日任务奖励
async def Daily_Task(self):
Expand All @@ -658,7 +662,8 @@ async def Daily_Task(self):
sleeptime = (utils.seconds_until_tomorrow() + 300)
else:
sleeptime = 350
Task().call_after('Daily_Task', sleeptime, self.user_id)
# Task().call_after('Daily_Task', sleeptime, self.user_id)
return sleeptime

async def Sign1Group(self, i1, i2):
json_response = await self.webhub.assign_group(i1, i2)
Expand All @@ -681,7 +686,8 @@ async def link_sign(self):
task = asyncio.ensure_future(self.Sign1Group(i1, i2))
tasklist.append(task)
results = await asyncio.gather(*tasklist)
Task().call_after('link_sign', 21600)
# Task().call_after('link_sign', 21600)
return 21600

async def send_gift(self):
if self.task_control['clean-expiring-gift']:
Expand All @@ -708,7 +714,8 @@ async def send_gift(self):
await self.send_gift_web(roomID, giftNum, bagID, giftID)
else:
print('未发现即将过期的礼物')
Task().call_after('send_gift', 21600)
# Task().call_after('send_gift', 21600)
return 21600

async def auto_send_gift(self):
# await utils.WearingMedalInfo()
Expand All @@ -734,7 +741,8 @@ async def auto_send_gift(self):
await self.full_intimate(list_gift, list_medal)

# self.printer_with_id(["# 自动送礼共送出亲密度为%s的礼物" % int(calculate)])
Task().call_after('auto_send_gift', 21600)
# Task().call_after('auto_send_gift', 21600)
return 21600

async def full_intimate(self, list_gift, list_medal):
json_res = await self.webhub.gift_list()
Expand Down Expand Up @@ -766,7 +774,8 @@ async def doublegain_coin2silver(self):
json_response0 = await self.webhub.doublegain_coin2silver()
json_response1 = await self.webhub.doublegain_coin2silver()
print(json_response0['msg'], json_response1['msg'])
Task().call_after('doublegain_coin2silver', 21600)
# Task().call_after('doublegain_coin2silver', 21600)
return 21600

async def sliver2coin(self):
if self.task_control['silver2coin']:
Expand All @@ -787,13 +796,16 @@ async def sliver2coin(self):
finish_app = False
if finish_app and finish_web:
sleeptime = (utils.seconds_until_tomorrow() + 300)
Task().call_after('sliver2coin', sleeptime, self.user_id)
# Task().call_after('sliver2coin', sleeptime, self.user_id)
return sleeptime
return
else:
Task().call_after('sliver2coin', 350, self.user_id)
# Task().call_after('sliver2coin', 350, self.user_id)
return 350
return

Task().call_after('sliver2coin', 21600, self.user_id)
# Task().call_after('sliver2coin', 21600, self.user_id)
return 21600

async def GetVideoExp(self, list_topvideo):
print('开始获取视频观看经验')
Expand Down Expand Up @@ -831,7 +843,8 @@ async def BiliMainTask(self):
if not share_av:
await self.GetVideoShareExp(list_topvideo)
# b站傻逼有记录延迟,3点左右成功率高一点
Task().call_after('BiliMainTask', utils.seconds_until_tomorrow() + 10800)
# Task().call_after('BiliMainTask', utils.seconds_until_tomorrow() + 10800)
return utils.seconds_until_tomorrow() + 10800


async def check(self, id):
Expand Down Expand Up @@ -900,7 +913,8 @@ async def judge(self):
# await asyncio.sleep(1)

self.printer_with_id([f'风纪委员会共获取{num_case}件案例,其中有效投票{num_voted}件'], True)
Task().call_after('judge', 3600)
# Task().call_after('judge', 3600)
return 3600



Expand All @@ -909,4 +923,8 @@ async def update(self, func, value):
# print('hhhhhhhhhhhhhhhh', self.user_id, func)
return await getattr(self, func)(*value)

async def daily_task(self, task_name):
time_delay = await getattr(self, task_name)()
time_delay += random.uniform(0, 25)
Task().call_after('daily_task', time_delay, (task_name,), self.user_id)

0 comments on commit 1a676d6

Please sign in to comment.