def calculatingMission(): cid = db.getMissionCid() if cid != False: print 'Processing calculating mission: cid = %d ...' % (cid) db.changeStatus('calculation', 'cid', cid, 'status', 1) data = db.fetchMissionData(cid) path = data['path'] inputData = dict() for item in data['input']: inputData[item['name']] = item['value'] print 'Copying plugin files into run/' if os.path.exists('run'): os.popen('rm -rf run') shutil.copytree(path, 'run') print 'Plugin copied.' filename = 'input_%d.json' % time.time() print 'Creating input file: %s into run/' % filename f = open('run/%s' % (filename), 'w') inputStr = f.write(json.dumps(inputData, ensure_ascii = False).encode('utf-8')) f.close() print 'Input file writed.' print 'Start running program...........' value = os.system('python run/core/main.py < run/%s > run/output' % (filename)) >> 8 f = open('run/output', 'rb') output = f.read() f.close() print 'Returned value:', value print 'Output:', output print 'Deleting folder run/ ....' os.popen('rm -rf run') print 'Deleted' print 'Writing calculation result into MySQL ...' if value != 0: output = '[程序返回错误代码:' + str(value) + ']\n' + output output = urllib.quote_plus(output) db.writeResult(cid, output) print 'Writed' status = value if value == 0: status = 2 else: if value == 1: status = 3 else: status = 5 db.changeStatus('calculation', 'cid', cid, 'status', status) print 'Calculation mission %d completed!' % (cid)
def downloadEp(): print "Downloading..." show_list = db.getShowList() flag = 0 for show in show_list: show_table_name = show[3] undone_list = db.getSpecificEpList(show_table_name, 0) if undone_list: for ep in undone_list: print "Try: %s" % (ep[0]) with open("log.out", "a+") as f: Popen(["transmission-gtk", ep[1]], stderr=f) flag = 1 db.changeStatus(show_table_name, ep[0], 1) if not flag: print "Clear, nothing downloaded."
async def addToGroup(group, arr): errores = 0 for user in arr: id_user = int(user[0]) await asyncio.sleep(5) print("Agregando a ", user) try: print() await client(InviteToChannelRequest(group, [id_user])) db.changeStatus((id_user, )) except (UserPrivacyRestrictedError): errores += 1 print(user, ": Usuario no permite por su configuracion") db.changeStatusError((id_user, )) except (UserNotMutualContactError): errores += 1 print(user, ":The provided user is not a mutual contact") db.changeStatusError((id_user, )) except (UserBotError): errores += 1 print(user, ":The provided user is a bot") db.changeStatusError((id_user, )) print('Usuarios con errores> ', errores)
def confirmPendingEps(): show_list = db.getShowList() flag = 0 for show in show_list: show_table_name = show[3] pending_list = db.getSpecificEpList(show_table_name, 2) if pending_list: for ep in pending_list: flag = 1 ep_name = ep[0] print "Do you want to download: %s?[y/n]" % (ep_name) while True: user_input = raw_input("==>") if user_input == "n": db.changeStatus(show_table_name, ep_name, 1) break elif user_input == "y": db.changeStatus(show_table_name, ep_name, 0) break else: print "Invalid input, please try again." if not flag: print "Clear nothing pending."
def gittingMission(): pid = db.getGittingPid() if pid != 0: print 'Processing gitting mission: pid = %d' % (pid) db.changeStatus('plugin', 'pid', pid, 'gitStatus', 3) path, git = db.fetchPluginData(pid) print 'Git:', git print 'Folder:', path if os.path.exists('%s' % (path)): print 'Path exists, deleting...' os.popen('rm -rf %s' % (path)) print 'Deleted.' value = os.system('git clone %s %s' % (git, path)) >> 8 if value == 0: db.changeStatus('plugin', 'pid', pid, 'gitStatus', 1) else: db.changeStatus('plugin', 'pid', pid, 'gitStatus', 4)
def echo_message(message): # Getting status status = db.getStatus(message.chat.id) if status == const.status[const.UNACTIVE]: # If user is 'unactive' bot.send_message(message.chat.id, "Ась?Не слышу!") elif status == const.status[const.ADDING_LINK]: message.text = message.text.lower() if message.text == "отмена": # If the cancel the action db.changeStatus(message.chat.id, const.status[const.UNACTIVE]) bot.send_message(message.chat.id, "Добавление группы отменено.") return # If a person wants to add a group, then you need to analyze it and display the answer if checkURL(message.text): # Changinst status + add a group db.changeStatus(message.chat.id, const.status[const.UNACTIVE]) # Checking status linkStatus = db.addLink(pathParser(message.text).path[1:], message.chat.id) if linkStatus == 0: # "All" is ok bot.send_message(message.chat.id, "Группа успешно добавлена ✅") elif linkStatus == 1: bot.send_message(message.chat.id, "Группа уже была добавлена") elif linkStatus == -1: bot.send_message(message.chat.id, "Произошла ошибка во время добавления группы") else: bot.send_message(message.chat.id, "Проверьте правильность введенный данных.\nДля выхода введите <strong>'Отмена'</strong>", parse_mode="HTML") elif status == const.status[const.REMOVING_LINK]: message.text = message.text.lower() if message.text == "отмена": # If we canceled all actions db.changeStatus(message.chat.id, const.status[const.UNACTIVE]) bot.send_message(message.chat.id, "Добавление группы отменено.") return # If a person wants to delete a group, then you need to analyze it and display a response if checkURL(message.text): # Changes the status, if it finds a group, then deletes it db.changeStatus(message.chat.id, const.status[const.UNACTIVE]) linkStatus = db.removeLink(pathParser(message.text).path[1:]) if linkStatus == 0: # All is ok bot.send_message(message.chat.id, "Группа успешно удалена ✅") elif linkStatus == 1: # Did not find such a group bot.send_message(message.chat.id, "Такой группы нет 😲") elif linkStatus == -1: # If error bot.send_message(message.chat.id, "Произошла ошибка во время добавления группы") else: bot.send_message(message.chat.id, "Проверьте правильность введенный данных.\nДля выхода введите <strong>'Отмена'</strong>", parse_mode="HTML") else: bot.send_message(message.chat.id, "Ась?Не слышу!")
def removelink(message): bot.send_message(message.chat.id, "Введите URL группы, которую Вы хотели бы удалить?") db.changeStatus(message.chat.id, const.status[const.REMOVING_LINK])
def addlink(message): bot.send_message(message.chat.id, "Введите URL группы, которую Вы хотели бы добавить?") db.changeStatus(message.chat.id, const.status[const.ADDING_LINK])