def show_logout(self): print(db.get_status()) if (db.get_status() == 0): self.logout() return self.dialog0 = pop.conf_pop('are you sure to logout', 'logout', lambda x: self.logout()) self.dialog0.open()
def run(self): db.set_status(1) util.clear_log() util.log("current cookie : " + COOKIE) for source in db.source_list(): util.log("source " + source['name'] + " started") url = "http://weixin.sogou.com/weixin?type=1&s_from=input&query=" + source['source'] + "&ie=utf8" # search result page profile_url = '' times = 0 while True: if db.get_status() != 1: util.log("stopped!") db.set_status(0) return # the cookie could be out of date res = util.request(url, {'Cookie': COOKIE}) if res is None: break soup = BeautifulSoup(res.text, 'lxml') profile = soup.select_one('.img-box a') if profile is not None: profile_url = profile.attrs['href'] break times = util.sleep_and_open(url, 'verify search url', times) # news profile page data = {} times = 0 while True: if db.get_status() != 1: util.log("stopped!") db.set_status(0) return res = util.request(profile_url) if res is None: break matches = re.findall(r'var msgList = (.*);', res.text) if len(matches) > 0: data = json.loads(matches[0]) break times = util.sleep_and_open(profile_url, 'verify profile url', times) if len(data) > 0: self.save(data, source) event.after_crawler_finished() db.set_status(0) util.log("done!")
def cng_scr(self, scr): if (db.get_status() == 0): self.golag = pop.conf_pop('Please Login to submit Feedback', 'Login', lambda x: self.GoLog()) self.golag.open() return self.main_widget.ids.scr_mngr.current = scr
def admin_page(): num_images = db.get_sample_count() num_human_annotations = db.get_human_annotation_count() datasets = db.get_datasets() enqueued = db.get_unprocessed_samples() models = db.get_models(details=True) model_id_to_name = {m['_id']: m['name'] for m in models} secondary_items = db.get_queued_samples() enqueued2 = [] for item in secondary_items: model_name = model_id_to_name.get(item['model_id'], '???') if 'sample_id' in item: target_name = db.get_sample_by_id(item['sample_id'])['filename'] elif 'validation_model_id' in item: target_name = model_id_to_name.get(item['validation_model_id'], '?!?') else: target_name = '!!!' enqueued2.append((model_name, target_name, str(item['_id']))) enqueued2 = sorted(enqueued2, key=lambda item: item[0]) status = [(status_name, db.get_status(status_id)) for status_name, status_id in status_ids] return render_template('admin.html', num_images=num_images, num_human_annotations=num_human_annotations, datasets=datasets, enqueued=enqueued, status=status, error=pop_last_error(), models=models, enqueued2=enqueued2)
async def main(): try: conn = db.get_conn() cur = conn.cursor() if check_cache(conn): print('即将更新缓存,速度较慢,请耐心等待') free_game = steam.get_free_games(False) cache_game = db.get_cache_game(cur, False) new_game = check_appids(free_game, cache_game) db.add_cache_game(cur, new_game) db.set_status(cur, 'update', int(time())) print('缓存更新完成') conn.commit() else: print('使用缓存数据') free_game = db.get_cache_game(cur, False) cur.close() bots = get_cfg('bot')['bot_name'] for i, bot in enumerate(bots, 1): print(f'进度{i}/{len(bots)} 机器人 {bot}') await process_bot(conn, bot, free_game) cur = conn.cursor() count = db.get_status('added') cur.close() conn.close() print(f'总计添加 {count} 个免费游戏') print('运行结束') except Exception as e: print('运行出错') print(e) traceback.print_stack() input('按回车键退出……')
def regis(self, name1, name2, email, phone, password): email = email.replace('.', '') data = { email: { 'name': name1 + ' ' + name2, 'phone': phone, 'password': password, 't1': '0', 't2': '0', 't3': '0', 't4': '0', 't5': '0', 't6': '0', 't7': '0', 't8': '0' } } response = set_firebase('', data) if response == 0: pop.error_pop('please turn on internet') self.dialog.dismiss() return db.change_all_db(name1 + ' ' + name2, phone, email, '0', '0', '0', '0', '0', '0', '0', '0') a = App.get_running_app() if a.info_state != 0: a.info_state = 1 if db.get_status() != '0': a.event_scr_effects = [1, 1, 1, 1, 1, 1] db.change_status('1') a.main_widget.ids.logStatus.text = 'logout' self.dialog.dismiss() Snackbar(text="registered successfully").show() self.manager.current = 'vute'
def color(self): posta = int(db.get_db(3)) if (db.get_status() == 0): self.ids.but.text = 'enroll' nocolor = self.theme_cls.primary_color elif (posta == 1): self.ids.but.text = 'registered' nocolor = self.theme_cls.green_color else: self.ids.but.text = 'enroll' nocolor = self.theme_cls.primary_color return nocolor
def enroll(self, status, event, no): if (db.get_status() == 0): self.golag = pop.conf_pop('Please Login to get Enroll', 'Login', lambda x: self.GoLog()) self.golag.open() return if status == 'registered': return self.dialog0 = pop.conf_pop('are you sure to enroll ' + event, 'enroll', lambda x: self.enroll2(event, no)) self.dialog0.open()
def check_cache(conn: db.sqlite3.Connection): '''检查缓存,判断是否需要更新''' cur = conn.cursor() cache_total = db.get_cache_game(cur, True) store_total = steam.get_free_games(True) update_time = db.get_status(cur, 'update') curr_time = int(time()) flag = curr_time - update_time > 604800 or store_total - cache_total > 50 print('需要更新缓存' if flag else '无需更新缓存') return flag
def load_info(self): if (db.get_status() == 0): self.golag = pop.conf_pop('Please Login to get info', 'Login', lambda x: self.GoLog()) self.golag.open() return if self.info_state == 0: self.main_widget.ids.scr_mngr.add_widget(person.lis()) self.info_state = 2 elif self.info_state == 1: self.main_widget.ids.scr_mngr.get_screen('info').clear_widgets() self.main_widget.ids.scr_mngr.get_screen('info').__init__() self.path_back.append('vute') self.main_widget.ids.scr_mngr.current = 'info'
def check_id(self, bot, update): answer = update.message.text if answer.isdigit(): # если ввели код user_id = int(answer) print(user_id) user = db.list_them([user_id])[0] # получаем словарь пользователя print(user) if user: # если вернулся не None self.users[user_id] = [update.message.chat_id, user['name']] self.chats[update.message.chat_id] = [user_id, user['name']] if db.get_status(user_id) == 'teacher': self.teachers[update.message.chat_id] = user_id print('users\t', self.users) print('chats\t', self.chats) print('teachers\t', self.teachers) if update.message.chat_id in self.teachers: menu = self.teacher_menu else: menu = self.student_menu bot.sendMessage( chat_id=update.message.chat_id, text='Здравствуйте, {} ({})! Что бы Вы хотели сделать?'. format(self.chats[update.message.chat_id][1], self.chats[update.message.chat_id][0]), reply_markup=menu) return ConversationHandler.END else: # id не нашлось в базе bot.sendMessage( chat_id=update.message.chat_id, text= 'К сожалению, такого id в нашей базе нет. Попробуйте снова или отправьте любое текстовое сообщение, чтобы зарегистрироваться.' ) return 'id' else: # совсем новенький user_ids = [user['user_id'] for user in db.list_all()] # кто есть в базе print('users in base\t', user_ids) user_id = random.randint(1000, 9999) # четырёхзначное число while user_id in user_ids: user_id = random.randint(1000, 9999) self.chats[update.message.chat_id] = [user_id] self.users[user_id] = [update.message.chat_id] update.message.reply_text('{}'.format(user_id)) bot.sendMessage( chat_id=update.message.chat_id, text= 'Тогда представьтесь, пожалуйста.\n*Если Вы студент:* введите фамилию, имя и группу через запятую в формате "Фамилия, Имя, группа".\n_Пример: Иванов, Иван, 15ФПЛ_\n*Если Вы преподаватель:* введите фамилию, имя и ключ доступа через запятую в формате "Фамилия, Имя Отчество, ключ доступа".\n_Пример: Иванов, Иван Иванович, key_\n\n*Внимательно проверяйте все данные! В текущей версии пока нет возможности их исправить.*', parse_mode='Markdown') return 'name'
async def process_bot(conn: db.sqlite3.Connection, bot: str, free_game: list): cur = conn.cursor() db_owned = db.get_owned_game(cur, bot) cur.close() not_owned = check_appids(free_game, db_owned) v_owned, v_not_owned = await asf_api.check_owned_game(bot, not_owned) cur = conn.cursor() db.add_owned_game(cur, bot, v_owned) conn.commit() cur.close() await asf_api.add_free_game(bot, v_not_owned) succ_owned, _ = await asf_api.check_owned_game(bot, v_not_owned) cur = conn.cursor() db.add_owned_game(cur, bot, succ_owned) count = db.get_status(cur, 'added') db.set_status(cur, 'added', count + len(succ_owned)) conn.commit() cur.close()
def dataset_info(dataset_id_str): print 'request.method', request.method if dataset_id_str == 'new' and request.method == 'POST': dataset_id = None dataset_info = None new_dataset_zoom = request.form['size'] else: dataset_id = ObjectId(dataset_id_str) dataset_info = db.get_dataset_by_id(dataset_id) new_dataset_zoom = None if dataset_info is None: return render_template("404.html") if request.method == 'POST': # File upload if dataset_info is not None: if db.is_readonly_dataset(dataset_info): set_error('Dataset is protected.') return redirect('/dataset/' + dataset_id_str) return upload_file(dataset_id, image_zoom=new_dataset_zoom) enqueued = db.get_unprocessed_samples(dataset_id=dataset_id) finished = db.get_processed_samples(dataset_id=dataset_id) for i, sample in enumerate(finished): sample['machine_distance'] = 1.0 / max( [0.001, sqrt(float(sample['machine_position_count']))]) sample['index'] = i errored = db.get_error_samples(dataset_id=dataset_id) # Get request data return render_template("dataset.html", dataset_name=dataset_info['name'], dataset_id=dataset_id_str, enqueued=enqueued, finished=finished, errored=errored, status=db.get_status('worker'), readonly=db.is_readonly_dataset(dataset_info), error=pop_last_error(), dataset_user=dataset_info.get('user'), image_zoom=dataset_info.get('image_zoom', 'default'))
def dataset_info(dataset_id_str): print 'request.method', request.method new_dataset_threshold_prob = None new_allow_reuse = False if dataset_id_str == 'new': print 'Creating new dataset' if request.method != 'POST': return redirect('/') dataset_id = None dataset_info = None new_dataset_zoom = request.form['size'] print 'Threshold prob:' print request.form['threshold'] try: v = float(request.form['threshold']) new_dataset_threshold_prob = min(max(v, 0.5), 1.0) print 'Specified thresh prob:', new_dataset_threshold_prob except ValueError: print 'Invalid threshold. Ignored.' try: new_allow_reuse = bool(request.form.get('reuseCheck')) print 'Specified allow reuse:', request.form.get( 'reuseCheck'), new_allow_reuse except ValueError: print 'Invalid reuse setting. Ignored.' else: dataset_id = ObjectId(dataset_id_str) db.access_dataset(dataset_id) dataset_info = db.get_dataset_by_id(dataset_id) new_dataset_zoom = None if dataset_info is None: return render_template("404.html") if request.method == 'POST': # File upload if dataset_info is not None: if db.is_readonly_dataset(dataset_info): set_error('Dataset is protected.') return redirect('/dataset/' + dataset_id_str) return upload_file(dataset_id, image_zoom=new_dataset_zoom, threshold_prob=new_dataset_threshold_prob, allow_reuse=new_allow_reuse) enqueued = db.get_unprocessed_samples(dataset_id=dataset_id) finished = db.get_processed_samples(dataset_id=dataset_id) for i, sample in enumerate(finished): sample['machine_distance'] = 1.0 / max( [0.001, sqrt(float(sample['machine_position_count']))]) sample['index'] = i errored = db.get_error_samples(dataset_id=dataset_id) threshold_prob = round(dataset_info.get('threshold_prob') or fc8_to_prob(default_prob_threshold), ndigits=3) # Get request data return render_template("dataset.html", dataset_name=dataset_info['name'], dataset_id=dataset_id_str, enqueued=enqueued, finished=finished, errored=errored, status=db.get_status('worker'), readonly=db.is_readonly_dataset(dataset_info), error=pop_last_error(), dataset_user=dataset_info.get('user'), image_zoom=dataset_info.get('image_zoom', 'default'), threshold_prob=threshold_prob)
#!/usr/bin/python """ this is the main script which calls the rest basically, it loads the model, gets the term candidates, and saves them for evaluation we use a sqlite3 DB to store the data and the ratings """ import fs_helpers, db from config import * # simple: connect to the sqlite DB get_db() # check if sqlite tables exists, else create them db.check_tables_exist(conf) # check if seed terms already in DB -- if not, insert them db.check_initial_seeds(conf) # find out in what iteration we are, load seed terms, etc db.get_status(conf) # load model model = fs_helpers.load_model(conf) # use word2vec to get term candidates candidates = model.most_similar(positive=conf['seeds'], topn=75) # save the term candidates db.save_candidates(conf, candidates)
def get_status(): return db.get_status('trainer')
def user_ui(name): actions = [ "balance", "withdraw", "deposit", "modify", "disable", "enable", "delete", "transactions", "log out" ] print(f""" ================================================================================ Welcome {name}! """ + "\n".join(actions) + """ ================================================================================ """) while True: # get action while True: action = input("Action: ").lower() if action in actions: break if action == "log out": break elif action == "delete": while True: password = input("Enter password: "******"Incorrect password.") confirmation = input("Confirm action? ").lower() if confirmation == "yes": db.delete_account(name) break elif action == "disable": if db.get_status(name): print(db.disable_account(name)) else: print("Account already disabled!") elif action == "enable": if not db.get_status(name): print(db.enable_account(name)) else: print("Account already enabled!") elif action == "modify": while True: password = input("Password:"******"New name (put none if no new name): ") while True: new_password = input( "New password (put none if no new password): ") confirm_password = input( "Confirm password (put none if no new password): ") if new_password != confirm_password: print("Password does not match!") else: break if new_name == "none": new_name = None if new_password == "none": new_password = None db.modify_account(name, password, new_name, new_password) print("Changes saved.") break else: print("Incorrect password.") elif action == "withdraw": db.withdraw(name) elif action == "deposit": db.deposit(name) elif action == "balance": print(db.get_user_balance(name))
def console_ui(): actions = [ "add", "remove", "enable", "disable", "transaction", "transactions", "accounts", "delete", "modify", "cancel", "process", "exit" ] print(f""" ================================================================================ Welcome Admin! """ + "\n".join(actions) + """ ================================================================================ """) while True: # get action while True: action = input("Action: ").lower() if action in actions: break if action == "transactions": print(db.get_transactions()) elif action == "exit": break elif action == "transaction": transaction_id = input("ID: ") transaction_id = int(transaction_id) print(db.get_transaction(transaction_id)) elif action == "accounts": print(db.get_accounts()) elif action == "add": name = input_existing_user() db.deposit(name) elif action == "remove": name = input_existing_user() db.withdraw(name) elif action == "delete": name = input_existing_user() confirm = input("Confirm action? ").lower() if confirm == "yes": db.delete_account(name) elif action == "enable": name = input_existing_user() if not db.get_status(name): db.enable_account(name) else: print("Account already enabled!") elif action == "disable": name = input_existing_user() if not db.get_status(name): db.enable_account(name) elif action == "modify": name = input_existing_user() password = db.get_password(name) new_name = input("New name (put none if no new name): ") while True: new_password = input( "New password (put none if no new password): ") confirm_password = input( "Confirm password (put none if no new password): ") if new_password != confirm_password: print("Password does not match!") else: break if new_name == "none": new_name = None if new_password == "none": new_password = None db.modify_account(name, password, new_name, new_password) print("Changes saved.") break
from db import new_status, get_status print(get_status('5Zt6zgqETBQq7Q3jxZox5'))
def run(self): # locking the thread self.lock = threading.Lock() print("Connection from: " + self.IPAddr + ":" + str(self.portAddr)) print("IP Connected: " + self.IPAddr) while True: try: # message incoming from the peer message = self.tcpClientSocket.recv(1024).decode().split() # if JOIN recieved # if message[0] == "JOIN": # if account exists # then account-exists is send as reponse if db.is_account_exist(message[1]): response = "account-exist" self.tcpClientSocket.send(response.encode()) # if account doesn't exists # account created and account success message is sent else: db.register(message[1], message[2], " ".join(message[3:])) #messagep[3] status response = "account-success" self.tcpClientSocket.send(response.encode()) # if CHANGE recieved # elif message[0] == "CHANGE": # if account exist # status changed mssg is sent if db.is_account_exist(message[1]): db.update_status(message[1]," ".join(message[2:])) response = "status-changed" self.tcpClientSocket.send(response.encode()) # if GET recieved # elif message[0] == "GET": # if account exists # current status is sent as mssg if db.is_account_exist(message[1]): status = db.get_status(message[1]) self.tcpClientSocket.send(status.encode()) # if LOGIN recieved # elif message[0] == "LOGIN": # if no account exist with the given username # flag is sent to the peer if not db.is_account_exist(message[1]): response = "Account-not-exist" self.tcpClientSocket.send(response.encode()) # if an account is already online with given username # flag is sent elif db.is_account_online(message[1]): response = "Account-online" self.tcpClientSocket.send(response.encode()) # if an account is log in successfully # extracts the password from the string else: # checks the password from looking into database retrievedPass = db.get_password(message[1]) if retrievedPass == message[2]: self.username = message[1] self.lock.acquire() try: tcpThreads[self.username] = self finally: self.lock.release() db.user_login(message[1], self.IPAddr, message[3]) # login-success is sent to the peer and udp thread is started to # watch the time response = "Account-success" self.tcpClientSocket.send(response.encode()) # udp server created self.udpServer = UDPServer(self.username, self.tcpClientSocket) # udp server started self.udpServer.start() # start the timer of udp self.udpServer.timer.start() # if wrong password then flag is sent else: response = "Wrong-password" self.tcpClientSocket.send(response.encode()) # if LOGOUT recieved # elif message[0] == "LOGOUT": # if user logouts removes usre from the online list of peer # thread removed from the list and socket is closed # timer udp thread cancels if len(message) > 1 and message[1] is not None and db.is_account_online(message[1]): db.user_logout(message[1]) # lock acquired self.lock.acquire() try: if message[1] in tcpThreads: # removes thread form the list del tcpThreads[message[1]] finally: # lock released self.lock.release() self.tcpClientSocket.close() self.udpServer.timer.cancel() break else: self.tcpClientSocket.close() break # if SEARCH recieved # elif message[0] == "SEARCH": # checks for accounts existsence if db.is_account_exist(message[1]): # if account is online search success is send if db.is_account_online(message[1]): peer_info = db.get_peer_ip_port(message[1]) response = "Success " + peer_info[0] + ":" + peer_info[1] self.tcpClientSocket.send(response.encode()) # else user not online is send else: response = "User-not-online" self.tcpClientSocket.send(response.encode()) # if no user with given name is found serach user not found is sent else: response = "User-not-found" self.tcpClientSocket.send(response.encode()) except OSError as oErr: pass
def get_status(secondary=False): status_id = 'sec_worker' if secondary else 'worker' return db.get_status(status_id)
def cli(): global parser global DB_FILENAME parser.add_argument( '--db-file', dest='db_file', action='store', default=DB_FILENAME, help='Specify SQLite DB file to be used (default: {}'.format( DB_FILENAME)) manage = parser.add_argument_group('Manage Tasks') manage.add_argument('-a', "--add", dest='task_definition', action='store', help='Add task') manage.add_argument('-Tn', "--task-name", dest='task_name', default="", action='store', help='') manage.add_argument('-Tt', "--task-type", dest='task_type', default="python", action='store', help='') manage.add_argument('-Tp', "--task-parameter", dest='task_parameter', default="", action='store', help='') manage = parser.add_argument_group('Run Tasks') manage.add_argument('-r', "--run", dest='run_single', default=0, action='count', help='Run task') manage.add_argument('-rL', "--run-loop", dest='run_loop', default=0, action='count', help='Run task in infinite loop') args = parser.parse_args() #Handle operations if args.task_definition: db.add_task(db_filename=args.db_file, definition=args.task_definition, tasktype=args.task_type, parameters=args.task_parameter) elif args.run_single: run_task(args.db_file) elif args.run_loop: while True: run_task(args.db_file) time.sleep(0.01) db.get_status(args.db_file)
from home import home_screen from kivymd.snackbar import Snackbar import listest import events import threading import multiprocessing import direction import feed import db import pop import prof import person import time import webbrowser state = int(db.get_status()) main_widget_kv = ''' #:import Toolbar kivymd.toolbar.Toolbar #:import ThemeManager kivymd.theming.ThemeManager #:import MDNavigationDrawer kivymd.navigationdrawer.MDNavigationDrawer #:import NavigationLayout kivymd.navigationdrawer.NavigationLayout #:import NavigationDrawerDivider kivymd.navigationdrawer.NavigationDrawerDivider #:import NavigationDrawerToolbar kivymd.navigationdrawer.NavigationDrawerToolbar #:import NavigationDrawerSubheader kivymd.navigationdrawer.NavigationDrawerSubheader #:import C kivy.utils.get_color_from_hex #:import Toolbar kivymd.toolbar.Toolbar #:import ThemeManager kivymd.theming.ThemeManager NavigationLayout:
def on_start(self): if (db.get_status() == 0): self.main_widget.ids.logStatus.text = 'login' from kivy.base import EventLoop EventLoop.window.bind(on_keyboard=self.hook_keyboard)