def parse_all(): # app and review list container app_list = list() review_list = list() # loop through the json file, first by app and then by reviews for idx, app in enumerate(islice(parse_all_json(), None)): a = App(app['id'], app['category'], app['company'], app['contentRating'], app['description'], app.get('devmail'), app.get('devprivacyurl'), app.get('devurl'), app['install'], app['name'], calculateSingularRating(app['rating']), app['screenCount'], app['size'], app['totalReviewers'], app['version']) app_list.append(a) for review in app['reviews']: r = Review(app['id'], review[0], review[1]) review_list.append(r) # only commit all the review for every 10 apps if idx % 25 == 0: session.add_all(app_list) session.commit() app_list = list() session.add_all(review_list) session.commit() review_list = list() # commit the rest of the review from the rest of the apps session.add_all(app_list) session.commit() session.add_all(review_list) session.commit() session.close()
def post(self): from app import db from models.app import App try: email = request.json.get('email').strip() # 校验邮件验证码 code = redis.get(email) if not code: return '验证码已失效', 400 if code != request.json.get('code'): return '验证码错误', 400 r = App() r.email = email r.name = request.json.get('name') r.id = uuid.uuid1().hex r.password = hashlib.sha256( request.json.get('password').strip().encode( 'utf8')).hexdigest() db.session.add(r) db.session.commit() return '注册成功', 200 except: db.session.rollback() return '注册失败', 400
def customer_register(): rds = g.rds db = g._db obj = json.loads(request.data) appid = obj.get("appid", 0) uid = obj.get("customer_id", "") name = obj.get("name", "") avatar = obj.get("avatar", "") if not appid: raise ResponseMeta(400, "invalid param") store_id = App.get_store_id(db, appid) if not store_id: raise ResponseMeta(400, "app do not support customer") if not uid: client_id = Customer.generate_client_id(rds) else: client_id = Customer.get_client_id(rds, appid, uid) if not client_id: client_id = Customer.generate_client_id(rds) Customer.set_client_id(rds, appid, uid, client_id) token = User.get_user_access_token(rds, appid, client_id) if not token: token = create_access_token() User.add_user_count(rds, appid, client_id) User.save_user(rds, appid, client_id, name, avatar, token) User.save_token(rds, appid, client_id, token) if obj.has_key("platform_id") and obj.has_key("device_id"): platform_id = obj['platform_id'] device_id = obj['device_id'] s = init_message_queue(appid, client_id, platform_id, device_id) if s: logging.error("init message queue success") else: logging.error("init message queue fail") resp = { "token":token, "store_id":store_id, "client_id":client_id, } data = {"data":resp} return make_response(200, data)
def customer_register(): rds = g.rds db = g._db obj = json.loads(request.data) appid = obj.get("appid", 0) uid = obj.get("customer_id", "") name = obj.get("name", "") avatar = obj.get("avatar", "") if not appid: raise ResponseMeta(400, "invalid param") store_id = App.get_store_id(db, appid) if not store_id: raise ResponseMeta(400, "app do not support customer") if not uid: client_id = Customer.generate_client_id(rds) else: client_id = Customer.get_client_id(rds, appid, uid) if not client_id: client_id = Customer.generate_client_id(rds) Customer.set_client_id(rds, appid, uid, client_id) token = User.get_user_access_token(rds, appid, client_id) if not token: token = create_access_token() User.add_user_count(rds, appid, client_id) User.save_user(rds, appid, client_id, name, avatar, token) User.save_token(rds, appid, client_id, token) if obj.has_key("platform_id") and obj.has_key("device_id"): platform_id = obj['platform_id'] device_id = obj['device_id'] s = init_message_queue(appid, client_id, platform_id, device_id) if s: logging.error("init message queue success") else: logging.error("init message queue fail") resp = { "token": token, "store_id": store_id, "client_id": client_id, } data = {"data": resp} return make_response(200, data)
def getApp(ID: Optional[int] = None, NAME: Optional[str] = None, API_KEY: Optional[str] = None): ds = datasource() ds.connect() global SQL, PARAM if ID is not None: SQL = "SELECT * FROM toolbox.APPS WHERE ID = %s" PARAM = (ID, ) elif NAME is not None: SQL = "SELECT * FROM toolbox.APPS WHERE NAME = %s" PARAM = (NAME, ) elif API_KEY is not None: SQL = "SELECT * FROM toolbox.APPS WHERE API_KEY = %s" PARAM = (API_KEY, ) ds.execute(SQL, PARAM) data = ds.fetch_dict() ds.close() return App(**data)
def customer_register(): rds = g.rds db = g._db obj = request.get_json(force=True, silent=True, cache=False) if obj is None: logging.debug("json decode err") raise ResponseMeta(400, "json decode error") appid = obj.get("appid", 0) uid = obj.get("customer_id", "") name = obj.get("name", "") avatar = obj.get("avatar", "") if not appid: raise ResponseMeta(400, "invalid param") store_id = App.get_store_id(db, appid) if not store_id: raise ResponseMeta(400, "app do not support customer") if not uid: client_id = Customer.generate_client_id(rds) else: client_id = Customer.get_client_id(rds, appid, uid) if not client_id: client_id = Customer.generate_client_id(rds) Customer.set_client_id(rds, appid, uid, client_id) token = User.get_user_access_token(rds, appid, client_id) if not token: token = create_access_token() User.add_user_count(rds, appid, client_id) User.save_user(rds, appid, client_id, name, avatar, token) User.save_token(rds, appid, client_id, token) resp = { "token":token, "store_id":store_id, "client_id":client_id, } data = {"data":resp} return make_response(200, data)
def create_app(self): try: app_name = self.view.get_str('app name') if app_name is None: raise ValueError(self.view.show_error('app name')) size = self.view.get_int('size') if size is None: raise ValueError(self.view.show_error('size')) installs = self.view.get_int('installs') if installs is None: raise ValueError(self.view.show_error('installs')) type_id = self.view.get_int('type id') if type_id is not None and not 1 <= type_id <= 3: raise ValueError(self.view.show_error('type id', 'input')) category_id = self.view.get_int('category id') if category_id is not None and not 1 <= category_id <= 47: raise ValueError(self.view.show_error('category id')) return App(0, app_name, size, installs, type_id, category_id) except Exception as err: self.view.show_error(err)
def post(self): email = request.json.get('email').strip() if not re.match( r'^[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+){0,4}@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+){0,4}$', email): return '邮箱格式错误' if code_send_limit(email): return '发送频繁,请稍后再试' from models.app import App from app import mail # 校验邮箱是否可用 if App.check_email_exist(email): return '邮箱已被使用', 400 code = random.randrange(100000, 999999) msg = Message( "验证码-User", body="您好,您正在进行身份验证,本次操作的验证码为:{},请在10分钟内完成验证。".format(code), recipients=[email]) mail.send(msg) redis.set(email, code, ex=10 * 60) return '发送成功', 200
def edit_app(self, app_id): app = self.model.get_app(app_id) self.view.list_str(app, 'App') options = ['app_name', 'size', 'installs', 'type_id', 'category_id'] while True: try: self.view.numerated_array(options) option = self.view.get_int('number') if option == 0: app_name = self.view.get_str('app name') if app_name is None: raise ValueError(self.view.show_error('app name')) app['app_name'] = app_name elif option == 1: size = self.view.get_int('size') if size is None: raise ValueError(self.view.show_error('size')) app['size'] = size elif option == 2: installs = self.view.get_int('installs') if installs is None: raise ValueError(self.view.show_error('installs')) app['installs'] = installs elif option == 3: type_id = self.view.get_int('type_id') if type_id is not None and not 1 <= type_id <= 3: self.view.show_error('type id', 'input') app['type_id'] = type_id elif option == 4: category_id = self.view.get_int('category id') if category_id is not None and not 1 <= category_id <= 47: raise ValueError(self.view.show_error('category id')) app['category_id'] = category_id else: raise ValueError('You need to enter action') return App(app['app_id'], app['app_name'], app['size'], app['installs'], app['type_id'], app['category_id']) except Exception as err: self.view.show_error(err)
def parse_apps(): # app container app_list = list() # loop through the json file, first by app and then by reviews for idx, app in enumerate(islice(parse_all_json(), 1)): a = App(app['id'], app['category'], app['company'], app['contentRating'], app['description'], app['install'], app['name'], calculateSingularRating(app['rating']), app['screenCount'], app['size'], app['totalReviewers'], app['version']) app_list.append(a) # only commit all the review for every 10 apps if idx % 25 == 0: session.add_all(app_list) session.commit() app_list = list() # commit the rest of the review from the rest of the apps session.add_all(app_list) session.commit() session.close()
def chat(): store = request.args.get('store') uid = request.args.get('uid') appid = request.args.get('appid') token = request.args.get('token') username = request.args.get('name', '') device_id = request.args.get('device_id', '') if not store and appid: store = App.get_store_id(g._db, int(appid)) print "store id:", store if not store: return render_template_string(error_html, error="非法的应用id") if not store: return render_template_string(error_html, error="未指定商店id") s = Store.get_store(g._db, int(store)) if s: name = s['name'] else: name = "" if uid and appid and token: return render_template("customer/pc_chat.html", host=config.HOST, customerAppID=int(appid), customerID=int(uid), customerToken=token, name=name, apiURL=config.APIURL, storeID=int(store)) #check cookie co_username = request.cookies.get('username', '') co_uid = request.cookies.get('uid') co_token = request.cookies.get('token') if co_username == username and co_uid and co_token: appid = config.ANONYMOUS_APP_ID uid = int(co_uid) token = co_token return render_template("customer/pc_chat.html", host=config.HOST, customerAppID=appid, customerID=uid, customerToken=token, name=name, apiURL=config.APIURL, storeID=int(store)) # 生成临时用户 rds = g.rds key = "anonymous_id" uid = rds.incr(key) appid = config.ANONYMOUS_APP_ID token = login_gobelieve(uid, username, config.ANONYMOUS_APP_ID, config.ANONYMOUS_APP_SECRET, device_id=device_id) resp = flask.make_response( render_template("customer/pc_chat.html", host=config.HOST, customerAppID=appid, customerID=uid, customerToken=token, name=name, apiURL=config.APIURL, storeID=int(store))) resp.set_cookie('token', token) resp.set_cookie('uid', str(uid)) resp.set_cookie('username', username) return resp
def chat(): store = request.args.get('store') uid = request.args.get('uid') appid = request.args.get('appid') token = request.args.get('token') username = request.args.get('name', '') device_id = request.args.get('device_id', '') if not store and appid: store = App.get_store_id(g._db, int(appid)) print "store id:", store if not store: return render_template_string(error_html, error="非法的应用id") if not store: return render_template_string(error_html, error="未指定商店id") s = Store.get_store(g._db, int(store)) if s: name = s['name'] else: name = "" if uid and appid and token: return render_template("customer/pc_chat.html", host=config.HOST, customerAppID=int(appid), customerID=int(uid), customerToken=token, name=name, apiURL=config.APIURL, storeID=int(store)) #check cookie co_username = request.cookies.get('username', '') co_uid = request.cookies.get('uid') co_token = request.cookies.get('token') if co_username == username and co_uid and co_token: appid = config.ANONYMOUS_APP_ID uid = int(co_uid) token = co_token return render_template("customer/pc_chat.html", host=config.HOST, customerAppID=appid, customerID=uid, customerToken=token, name=name, apiURL=config.APIURL, storeID=int(store)) # 生成临时用户 rds = g.rds key = "anonymous_id" uid = rds.incr(key) appid = config.ANONYMOUS_APP_ID token = login_gobelieve(uid, username, config.ANONYMOUS_APP_ID, config.ANONYMOUS_APP_SECRET, device_id=device_id) resp = flask.make_response(render_template("customer/pc_chat.html", host=config.HOST, customerAppID=appid, customerID=uid, customerToken=token, name=name, apiURL=config.APIURL, storeID=int(store))) resp.set_cookie('token', token) resp.set_cookie('uid', str(uid)) resp.set_cookie('username', username) return resp
async def fetch_app(self, app: App, session: ClientSession) -> App: async with session.get(app.url) as response: response.raise_for_status() data = await response.json() data.update(app.dict(include={"id", "title", "url"})) return App.parse_obj(data)
window = pygame.display.set_mode((700, 750)) #set width & height of display pygame.display.set_caption("Twitter Sentpy") #set window name background_color = (255, 255, 255) #PIPELINE pipeline = NlpPipeline(open("twitter_emotions/nlp/tweets_dataset.txt", "r", encoding="utf8")) pipeline.run_pipeline() #SOM som = Som(pipeline.bag_of_words, None, 15, 15, 0.4, 1000) som.train() programIcon = pygame.image.load('./twitter_emotions/assets/bot_icon.png') newbtn = pygame.image.load('./twitter_emotions/assets/plusle_icon.png') pygame.display.set_icon(programIcon) app = App(window, pipeline, som) new_btn = EButton(20,30, newbtn) #game starts while True: window.fill(background_color) #window.blit(bg, (0, 0)) app.draw_app() new_btn.draw_button(window) pygame.display.update() for event in pygame.event.get(): pos = pygame.mouse.get_pos() if event.type == pygame.QUIT: sys.exit() app.search_text_write(event)