def post_config(): # Update all configurations for key, value in request.form.items(): db.insert('UPDATE config SET config_value=? WHERE config_key=?', [value, key]) return jsonify(status='OK')
def output(history, test, pred_ans, target, algo, data_type, epoch, optimizer, dropout): logLoss = round(log_loss(test[target].values, pred_ans), 4) auc = round(roc_auc_score(test[target].values, pred_ans), 4) print("test LogLoss", logLoss) print("test AUC", auc) history_curves(history) insert(algo, data_type, epoch, optimizer, dropout, logLoss, auc) print("Successfully insert ...")
def put_sensor(sensor_name): body = request.get_json() # Insert new value in database db.insert( 'INSERT INTO sensors (sensor_name, sensor_value, sensor_time) VALUES (?, ?, ?)', [sensor_name, body.get('value'), datetime.now()]) return jsonify(status='OK')
def getCommentLetv(cls, playlink, moviename): if playlink != '': vid = playlink.split('/')[-1].split('.')[0] for i in range(1, 120): jslink = 'http://api.my.letv.com/vcm/api/g?type=video&xid='+str(vid)+'&page='+str(i) source = Request.getSource(jslink) try: pat = re.compile(r'content":"(.*?)"') commentlist = pat.findall(source) for comm in commentlist: unescomm = pyunescape.pyunescape(comm) if unescomm is not None and unescomm != "": db.insert((moviename, 'letv', unescomm)) except: continue
def getCommentFunshion(cls, playlink, moviename): if playlink != '': vid = playlink.split('/')[-2] for page in range(1, 31): jslink = 'http://q.funshion.com/ajax/get_comment/media/'+vid+'/all?pg='+str(page) source = Request.getSource(jslink) try: pat = re.compile(r'content":"(.*?)"') commentlist = pat.findall(source) for comm in commentlist: unescomm = pyunescape.pyunescape(comm) if unescomm is not None and unescomm != "": db.insert((moviename, 'funshion', unescomm)) except: continue
def insert_test(): test_document = {"_id": "test_data", "name": "first test"} test_fail_document = {"_id": "test_data", "name": "second test"} # Check a normal insert. if not db.insert(COLLECTION, test_document): print "insert_test: Normal insert failed" return False # Check a conflicting insert. if db.insert(COLLECTION, test_fail_document): print "insert_test: Conflicting insert failed" return False return True
def getCommentYouku(cls, playlink, moviename): if playlink != '': vid = playlink.split('_')[-1].split('.')[0] for page in range(1, 100): jslink = 'http://comments.youku.com/comments/~ajax/vpcommentContent.html?__ap={%22videoid%22:%22'+vid+'%22,'+'%22page%22:'+str(page)+'}' commentsource = Request.getSource(jslink) try: pat = re.compile(r'content_(.*?)<br') commentlist = pat.findall(commentsource) for comm in commentlist: comm = comm.split('">') unescomm = pyunescape.pyunescape(comm[2]) if unescomm is not None and unescomm != "": db.insert((moviename, 'youku', unescomm)) except: continue
def add_item_to_database(self): """ SQL request """ # items_base sql1 = "INSERT INTO items_base VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" db.insert(sql1, self.data) print("[items_base] Chargé!") # catalog_items sql2 = "INSERT INTO catalog_items VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" db.insert(sql2, self.data_catalog) print("[catalog_items] Chargé!") with open("files/log.txt", "a") as log: log.write("ID: " + self.data[0] + " | item_name: " + self.data[2] + "\n")
def find_test(): # Setup test. db.insert(COLLECTION, {"name": "test_data"}) selector = {"name": "test_data"} fail_selector = {"name": "fail_data"} # Check a normal find. if len(db.find(COLLECTION, selector)) != 1: print "find_test: Normal selection failed" return False # Check an empty find. if len(db.find(COLLECTION, fail_selector)) != 0: print "find_test: Empty selection failed" return False return True
def getCommentIqiyi(cls, playlink, moviename): if playlink != '': source = Request.getSource(playlink) if source is not None: m = re.search(r'qitanid="\w+"', source) vid = m.group(0).split('"')[1] for page in range(1, 50): jslink = 'http://api.t.iqiyi.com/qx_api/comment/get_video_comments?page='+str(page)+'&qitanid='+str(vid) commentsource = Request.getSource(jslink) pat = re.compile(r'content":"(.*?)"') try: commentlist = pat.findall(commentsource) for comm in commentlist: unescomm = pyunescape.pyunescape(comm) if unescomm is not None and unescomm != "": db.insert((moviename, 'iqiyi', unescomm)) except: continue
def find_stress_test(): # Setup test. num_documents = 50 for i in range(num_documents): db.insert(COLLECTION, {"name": i}) # Check that all the documents are returned. if len(db.find(COLLECTION)) != num_documents: print "find_stress_test: All document selection failed." return False # Check that the correct number of documents are returned. limit = 7 if len(db.find(COLLECTION, limit=limit)) != limit: print "find_stress_test: Limited document selection failed." return False return True
def __call__(self, args): for name in args.task_name: data = { 'name': name, 'category': args.category, 'completed': False, 'parent': None } eid = db.insert(data) print('Added task T{}: {}'.format(eid, name))
def getCommentSohu(cls, playlink, moviename): if playlink != '': source = Request.getSource(playlink) if source is not None: m = re.search(r'vid\s*=\s*[\"\']\w+[\"\']', source) vid = m.group(0).split('"')[1] n = re.search(r'playlistId\s*=\s*[\"\']\w+[\"\']', source) playlistid = n.group(0).split('"')[1] jslink = 'http://access.tv.sohu.com/reply/list/1000_' + \ str(playlistid) + '_' + str(vid) + '_0_2000.js' commentsource = Request.getSource(jslink) try: comments = re.search(r'\[.*\]', commentsource) comments = comments.group(0).replace("'",'"') pat = re.compile(r'content":"(.*?)"') commentlist = pat.findall(comments) for comm in commentlist: unescomm = pyunescape.pyunescape(comm) if unescomm is not None and unescomm != "": db.insert((moviename, 'sohu', unescomm)) except: pass
def create_list(): json = request.get_json() id = db.create_id("lists") title = json["title"] id_user = json["id_user"] if not db.verify_register("users", "id", id_user): return jsonify(error(400, "User not exists")) elif db.verify_register("lists", "id", id): return jsonify(error(400, "List already exists")) else: # create instance list_user = List(id, id_user, title, datetime.datetime.utcnow()) # insert into database if db.insert("lists", list_user.to_dict()): return jsonify(list_user.to_dict()) else: return jsonify(error(203, "Not Allowed"))
def create_task(): json = request.get_json() id = db.create_id("tasks") title = json["title"] description = json["description"] id_list = json["id_list"] if not db.verify_register("lists", "id", id_list): return jsonify(error(400, "List not exists")) elif db.verify_register("tasks", "id", id): return jsonify(error(400, "Task already exists")) else: # create instance task = Task(id, id_list, title, description, datetime.datetime.utcnow()) # insert into database if db.insert("tasks", task.to_dict()): return jsonify(task.to_dict()) else: return jsonify(error(203, "Not Allowed"))
def process_data(self, data): """Process data from a POST or PUT call""" import jsonschema jsonschema.validate(data, self.schema) return db.insert(data)
def insert(self): if not db.find_one('user', {'email': self.email}): db.insert(collection='user', data=self.json())
from attr import asdict from database import db, Player from battler import Battler res = db.search(Player.exists()) if res: print(res[0]['player']) else: name = input("Enter your name: ") battler = Battler(name=name) db.insert({'player': asdict(battler)})
def save_to_mongo(self): db.insert("sensor_data", self.json())