Example #1
0
def zcn(s,id):
    '''
      查询淘宝中此商品信息,s为关键词,id为生成id,将查到的商品保存到数据库id表中并返回成功数目
      参数说明:
         s: 关键词
    '''
    global pic,name,price,deal
    pic=[];name=[];price=[];deal=[] #清零
    #将关键词转成网页编码
    s=urllib.quote(s)
    s.replace('%20','+')
    url='http://www.amazon.cn/s/field-keywords=%s'%s
    start=0 #起始位置
    text="" #查询内容
    db.create(id)
    text=requests.get(url).text#requsts经测试比urllib快
    find(text)
    s=[1,2,3,4,5,6,7]
    for i in range(len(name)): #按格式写入文件
        s[0]=name[i][1].encode('gbk');s[1]=pic[i].encode('gbk');s[2]=name[i][0].encode('gbk');
        s[3]=(price[i].encode('gbk')).replace(',','')
        s[4]=-1;s[5]=-1;s[6]='亚马逊'
        #print s
        db.add(id,s)
    return len(name)    
Example #2
0
def taobao(s,id):
    '''
      查询淘宝中此商品信息,s为关键词,id为生成id,将查到的商品保存到数据库id表中并返回成功数目
      参数说明:
         s: 关键词
    '''
    global pic,name,price,deal
    pic=[];name=[];price=[];deal=[] #清零
    #将关键词转成网页编码
    s=urllib.quote(s)
    s.replace('%20','+')
    url='http://s.taobao.com/search?q=%s&s='%s
    start=0 #起始位置
    text="" #查询内容
    db.create(id)
    while start==0 or find(text)!=0:
        text=requests.get(url+str(start)).text.encode('u8')#requsts经测试比urllib快
        start+=44
        if start>220:break #只抓取前5页
    s=[1,2,3,4,5,6,7]
    for i in range(len(name)): #按格式写入文件
        s[0]=name[i][1].decode('u8').encode('gbk');s[1]=pic[i];s[2]=name[i][0];s[3]=price[i][0]
        s[4]=price[i][1];s[5]=deal[i];s[6]='淘宝'
        #print s
        db.add(id,s)
    return len(name)    
Example #3
0
def insert_all():
    last_updated = perfectmind.last_updated()
    db.create()
    insert_all_attendance(last_updated)
    insert_all_clients(last_updated)
    insert_all_teachers(last_updated)
    insert_all_events(last_updated)
Example #4
0
 def setUp(self):
     flask.app.config['TESTING'] = True
     self.app = flask.app.test_client()
     png_dir = os.path.join(datadir, 'png')
     if not os.path.isdir(png_dir):
         os.makedirs(png_dir)
     open(os.path.join(datadir, 'update.log'), 'a')
     db.create()
Example #5
0
def main():
    engine = db.get_engine()

    print "Creating database..."
    db.create(engine)

    init_data(engine)
    print "Successfully set up."
Example #6
0
 def setUp(self):
     flask.app.config['TESTING'] = True
     self.app = flask.app.test_client()
     png_dir = os.path.join(datadir, 'png')
     if not os.path.isdir(png_dir):
         os.makedirs(png_dir)
     open(os.path.join(datadir, 'update.log'), 'a')
     db.create()
Example #7
0
def main():
    engine = db.get_engine()

    print "Creating database..."
    db.create(engine)

    init_data(engine)
    print "Successfully set up."
Example #8
0
    def create_mapping_table(context, data_dict, mapped_columns):
        """Create table to store the metadata of mapped column names

        :param mapped_columns: dict, mapped column names
        :param context: context
        :param data_dict: data_dict
        """
        datastore_dict = {}

        # Creating name for the mapping datastore
        try:
            dataset_name = data_dict.get('resource').get('name')
            data_dict['resource']['name'] = dataset_name + '_mapping'

        except Exception:

            resource_data = toolkit.get_action('resource_show')(
                context, {
                    'id': data_dict.get('resource_id')
                })

            dataset_name = resource_data.get('name')
            data_dict.update({'resource': {}})
            data_dict['resource'].update({'name': dataset_name + '_mapping'})
            data_dict['resource'].update(
                {'package_id': resource_data.get('package_id')})

        resource_dict = toolkit.get_action('resource_create')(
            context, data_dict['resource'])
        resource_id = resource_dict['id']
        # package_id = data_dict['resource']['package_id']

        datastore_dict['connection_url'] = data_dict['connection_url']

        datastore_dict['resource_id'] = str(resource_id)
        fields = [{
            'id': 'mapped_column',
            'type': 'text'
        }, {
            'id': 'original_name',
            'type': 'text'
        }]

        datastore_dict['fields'] = fields
        records = []
        for key, value in mapped_columns.iteritems():
            row = {'mapped_column': key, 'original_name': value}
            records.append(row)

        datastore_dict['records'] = records
        datastore_dict['primary_key'] = 'mapped_column'

        db.create(context, datastore_dict, False)
Example #9
0
 def add_in_db(self):
     header = ["sys_num", "name", "fname", "phone", "uid", "nik", "wo"]
     data = []
     try:
         for i in range(7):
             data.append(self.table.item(0, i).text())
     except AttributeError:
         QtWidgets.QMessageBox.about(self, 'Ошибка', f'{i + 1}  колонка пустая')
         return 1
     db.create({header[0]: data[0], header[1]: data[1], header[2]: data[2], header[3]: data[3], header[4]: data[4],
                header[5]: data[5], header[6]: data[6]})
     QtWidgets.QMessageBox.about(self, 'Успешно', 'Элемент в базе!')
     self.table.setRowCount(0)
     self.add_btn.setVisible(False)
Example #10
0
def virtualadd():
    if request.method == 'GET':
        return render_template('assets/virtuals/virtualadd.html', display = dis)
    else:
        data = request.form.to_dict()
        util.WriteLog('infoLogger').warning('%s add virtual %s' % (session['username'], data['hostname']))
        return json.dumps(db.create(data, 'virtuals'))
Example #11
0
def old_initialize():
    engine, session = db.create("sqlite:///db.sqlite3")
    db.create_tables(engine)
    p_snps = 0
    p_pubs = 0
    snps = get_complete_rsids()
    for s in snps:
        time.sleep(.1)
        pubs = get_pmids(s)
        if len(pubs) > 0:
            p_snps = p_snps + 1
            print("Processed {} snps".format(p_snps))
            for p in pubs:
                if not db.check_snp(session=session, id=s, pub=p):
                    db.add_snp(session, s, p)
                if not db.check_publication(session=session, id=p):
                    info = get_publication(p)
                    db.add_publication(session,
                                       id=p,
                                       title=info["title"],
                                       abstract=info["abstract"])
                p_pubs = p_pubs + 1
                print("Processed {} pubs".format(p_pubs))
    db.close(session)
    return ()
Example #12
0
def add_new_idcinfo(params):
    new_params = {}
    new_params['idcname'] = params.get('idcname')
    new_params['date'] = params.get('date')
    new_params['cabinet'] = params.get('cabinet')
    new_params['cabinet_price'] = params.get('cabinet_price')
    new_params['host_amount'] = params.get('host_amount')
    new_params['bandwidth'] = params.get('bandwidth')
    new_params['bandwidth_price'] = params.get('bandwidth_price')
    new_params['bandwidth_amount'] = float(params.get('bandwidth')) * float(params.get('bandwidth_price'))
    new_params['combined'] = float(params.get('host_amount')) + float(new_params['bandwidth_amount'])
    new_params['status'] = params.get('status')
    new_params['info'] = params.get('info')

    # idcname =  params.get('idcname')
    # date = params.get('date')
    # cabinet = params.get('cabinet')
    # cabinet_price = params.get('cabinet_price')
    # host_amount = params.get('host_amount')
    # bandwidth = params.get('bandwidth')
    # bandwidth_price = params.get('bandwidth_price')
    # bandwidth_amount = float(bandwidth) * float(bandwidth_price)
    # combined = float(host_amount) + float(bandwidth_amount)
    # status = params.get('status')
    # info = params.get('info')
    # print date,idcname,cabinet,cabinet_price,host_amount,bandwidth,bandwidth_price,bandwidth_amount,combined,status,info
    # _sql = 'insert into idc_data(date,idcname,cabinet,cabinet_price,host_amount,bandwidth,bandwidth_price,bandwidth_amount,combined,status,info) values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)'
    # _args = (date,idcname,cabinet,cabinet_price,host_amount,bandwidth,bandwidth_price,bandwidth_amount,combined,status,info)
    _sql_count,rt_list = db.create(new_params,'idc_bill')
    if _sql_count != 0:
        return True ,'添加成功'
    return False ,'添加失败'
Example #13
0
def add_new_idcinfo(params):
    new_params = {}
    new_params['idcname'] = params.get('idcname')
    new_params['date'] = params.get('date')
    new_params['cabinet'] = params.get('cabinet')
    new_params['cabinet_price'] = params.get('cabinet_price')
    new_params['host_amount'] = params.get('host_amount')
    new_params['bandwidth'] = params.get('bandwidth')
    new_params['bandwidth_price'] = params.get('bandwidth_price')
    new_params['bandwidth_amount'] = float(params.get('bandwidth')) * float(
        params.get('bandwidth_price'))
    new_params['combined'] = float(params.get('host_amount')) + float(
        new_params['bandwidth_amount'])
    new_params['status'] = params.get('status')
    new_params['info'] = params.get('info')

    # idcname =  params.get('idcname')
    # date = params.get('date')
    # cabinet = params.get('cabinet')
    # cabinet_price = params.get('cabinet_price')
    # host_amount = params.get('host_amount')
    # bandwidth = params.get('bandwidth')
    # bandwidth_price = params.get('bandwidth_price')
    # bandwidth_amount = float(bandwidth) * float(bandwidth_price)
    # combined = float(host_amount) + float(bandwidth_amount)
    # status = params.get('status')
    # info = params.get('info')
    # print date,idcname,cabinet,cabinet_price,host_amount,bandwidth,bandwidth_price,bandwidth_amount,combined,status,info
    # _sql = 'insert into idc_data(date,idcname,cabinet,cabinet_price,host_amount,bandwidth,bandwidth_price,bandwidth_amount,combined,status,info) values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)'
    # _args = (date,idcname,cabinet,cabinet_price,host_amount,bandwidth,bandwidth_price,bandwidth_amount,combined,status,info)
    _sql_count, rt_list = db.create(new_params, 'idc_bill')
    if _sql_count != 0:
        return True, '添加成功'
    return False, '添加失败'
Example #14
0
def register():
    email = request.form['uname']
    fName = request.form['fname']
    lName = request.form['lname']
    password = request.form['psw']
    passwordConfirm = request.form['psw2']
    # print("request.form['psw']")
    image = request.files['img']

    imageB64 = base64.b64encode(image.read())

    print(imageB64)

    # print("request.files['img']")
    # image.save(secure_filename(image.filename))
    # print("f.save(secure_filename(f.filename))")
    _, code = db.validate(email)
    print(code)
    if code == 200:
        # username conflict
        return jsonify(message="username already registered", code=404)
    elif password != passwordConfirm:
        # password not matching
        return jsonify(message="password do not match", code=201)
    else:
        data = {'password': password, 'fName': fName, 'lName': lName, 'img': imageB64}
        _, chkCode = db.create(email, data)

        if chkCode == 200:

            return jsonify(message="Account created", code=200)
        else:

            return jsonify(message='Database insert error', code=404)
Example #15
0
def set_user():
    ''' Set username and doggy type of ip, adds ip if not found '''
    requires = ["name", "character", "location"]
    if not request.json:
        return jsonify({"msg": "not json"}), 400
    for req in requires:
        if not request.json.get(req):
            return jsonify({"msg": "no {}".format(req)}), 400

    user_ip = request.remote_addr
    name = request.json["name"]
    character = request.json["character"]
    location = request.json["location"]
    user = db.get_user_by_ip(user_ip)
    if user is None:
        user = db.create("User", ip=user_ip, name=name,
                         character=character,
                         form=character, location=location) 
    else:
        user = db.update(user_ip, name=name,
                         character=character,
                         form=character, location=location) 

    user.touch()
    if user is None:
        return jsonify({})
    else:
        ret = user.to_dict()
        del ret["ip"]
        return jsonify({"user": ret})
Example #16
0
def inneradd():
    if request.method == 'GET':
        return render_template('assets/inner/inneradd.html')
    else:
        inner = request.form.to_dict()
        reason = db.create(inner, 'innerServer')
        return json.dumps(reason)
Example #17
0
def inneradd():
    if request.method == 'GET':
        return render_template('assets/inner/inneradd.html')
    else:
        inner = request.form.to_dict()
        reason = db.create(inner, 'innerServer')
        return json.dumps(reason)
Example #18
0
def dump_scripts():
    '''
        Upload script from file
    '''
    user_ip = request.remote_addr
    user = db.get_user_by_ip(user_ip) 
    if user is None:
        return jsonify({"msg": "ip not set"}), 401
    user.touch()

    f = request.files['file']
    filename = f.filename
    row = 0
    col = 0
    text = f.read().decode("utf-8")

    if user.form == 'ghost':
        return jsonify({"msg": "you're a ghost"})


    user.material += 1;
    file_obj = create_file(user_ip, filename, text, row, col)
    material = nest.test_file(file_obj)
    
    new_file = db.create("Script", user_id=user.id, material=material,
              filename=filename, filetext=text, filetype=file_obj['filetype'],
              row=row, col=col, location=user.location)
    db.save()
    res = user.to_dict()
    del res['ip']
    script = new_file.to_dict()
    script['user'] = res
    return jsonify({"script" : script, "user": res})
Example #19
0
def virtualadd():
    if request.method == 'GET':
        return render_template('assets/virtuals/virtualadd.html', display=dis)
    else:
        data = request.form.to_dict()
        util.WriteLog('infoLogger').warning(
            '%s add virtual %s' % (session['username'], data['hostname']))
        return json.dumps(db.create(data, 'virtuals'))
Example #20
0
def backupServer_monitor_cron():
    ip_list = db.get_list(['wan_ip','qufu','hostname'], 'virtuals')
    for ip in ip_list:
        dirname = '/data/mongobackup/' + ip['wan_ip']
        backNum = util.paramiko_command('121.201.72.22', 'ls %s|wc -l' % dirname)
        ip['backNum'] = backNum
        backName = util.paramiko_command('121.201.72.22', 'ls -rt %s|tail -1' % dirname)
        ip['backName'] = backName
        backSize = util.paramiko_command('121.201.72.22', "ls -lrt --block-size=M %s |tail -1|awk '{print $5}'" % dirname)
        ip['backSize'] = backSize
        if len(ip['backSize']) >= 5:
            ip['backSize'] = str(round(float(float(ip['backSize'][0:-1]) / 1024), 2)) + 'G'
        if len(json.loads(db.get_one(['wan_ip'], "wan_ip='%s'" % str(ip['wan_ip']), 'backupServerMonitor'))) > 1:
            db.delete("wan_ip='%s'" % ip['wan_ip'], 'backupServerMonitor')
            db.create(ip, 'backupServerMonitor')
        elif len(json.loads(db.get_one(['wan_ip'], "wan_ip='%s'" % str(ip['wan_ip']), 'backupServerMonitor'))) == 1:
            db.update(ip, "wan_ip='%s'" % ip['wan_ip'], 'backupServerMonitor')
        elif len(json.loads(db.get_one(['wan_ip'], "wan_ip='%s'" % str(ip['wan_ip']), 'backupServerMonitor'))) == 0:
            db.create(ip, 'backupServerMonitor')
Example #21
0
def roolBack():
    verId = request.form.get('verId')
    columns = ['version']
    where = 'id=%s' % verId
    version = json.loads(db.get_one(columns, where, 'codePublish'))['version']
    client = pysvn.Client()
    client.callback_get_login = getLogin
    if os.path.exists(svnRoolBackPath):
        shutil.rmtree(svnRoolBackPath)
    rv = pysvn.Revision(pysvn.opt_revision_kind.number, version)
    client.export(svnurl, svnRoolBackPath, revision=rv)
    date = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    data = dict({'version': version, 'introduction': '回滚到版本', 'username': session['username'], 'date': date})
    db.create(data, 'codePublish')

    cmd = 'rsync -avzLPq --delete %s/* [email protected]:/data/oop/cmdb' % svnRoolBackPath
    subprocess.call(cmd, shell=True)
    paramiko_command('tools.uc.ppweb.com.cn', 'cd /data/oop;bash run.sh')
    paramiko_command('tools.uc.ppweb.com.cn', "sed -i '/代码发布/d' /data/oop/cmdb/app/templates/base.html")
    return json.dumps({'code': 0, 'errmsg': '回滚成功'})
Example #22
0
def create():
    if current_user.is_authenticated:

        return connection.create(request.args.get('firstname'),
                                 request.args.get('lastname'),
                                 request.args.get('username'),
                                 request.args.get('password'),
                                 request.args.get('email'),
                                 request.args.get('active'))
    else:
        return "please login"
Example #23
0
def cabinetadd():
    if request.method == 'GET':
        idc_columns = ['id', 'name', 'address', 'adminer', 'phone', 'cabinet_num', 'switch_num']
        idcs = db.get_list(idc_columns, 'idc')
        idcinfo = []
        for idc in idcs:
            idcinfo.append({'id': idc['id'], 'name': idc['name']})
        return render_template('assets/cabinet/cabinetadd.html', idcinfo=idcinfo, display = dis)
    else:
        data = request.form.to_dict()
        util.WriteLog('infoLogger').warning('%s add cabinet %s' % (session['username'], data['name']))
        return json.dumps(db.create(data, 'cabinet'))
Example #24
0
    def finalize_db(self):
        main = self.ui.masterpw2_entry.text()
        conf = self.ui.confirmmasterpw2_entry.text()
        if main == conf:
            master_pw = main.encode('utf-8')
            self.master_hash = process.hasher(master_pw)
            self.key,salt = process.pbkdf(master_pw)

            if self.filepath:
                db.create(self.filepath)
                db.update(self.filepath, self.master_hash, salt)
                
                QMessageBox(QMessageBox.Information,'Success','Database has been created').exec()
                
                self.refresh_page2()
                self.display()
                self.ui.stacked_wid.setCurrentIndex(2)
            else:
                QMessageBox(QMessageBox.Warning,'Error','Please select a path for database first').exec()
        else:
            QMessageBox(QMessageBox.Warning,'Error','Those passwords do not match, try again').exec()
Example #25
0
def create_contact():
    status = False

    if request.method == 'POST':
        if request.form['name'] and request.form['number']:
            name = request.form['name']
            number = request.form['number']

            if db.create(name, number):
                status = True

    return jsonify({"status": status})
Example #26
0
def upload():
    files = request.files.get('files')
    filename =  files.filename
    if not filename:
        return redirect('/gm_update/')
    filepath = os.path.join('/home/op/gm_wars/', filename)
    files.save(filepath)

    cmd = 'cd /home/op/gm_wars/;./update_war.pl %s' % filename
    cmd_result = paramiko_command('tools.uc.ppweb.com.cn', cmd)
    WriteLog('infoLogger').info(cmd_result)
    if cmd_result != 1:
        status = 0
    else:
        status = 1

    update_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    username = session['username']
    info = dict({'filename': filename, 'update_time': update_time, 'status': status, 'username': username})
    db.create(info, 'gm_update')
    return redirect('/gm_update/')
Example #27
0
def build(dump='dump:downloads'):
    downloads = ParseDownloads().run(input=[dump])
    print_errors(downloads)

    find_data_range = FindDataRange().run(input=[downloads.wait()])
    print_errors(find_data_range)
    data_range = dict(result_iterator(find_data_range.results()))
    print data_range
    find_data_range.purge()

    histograms = BuildHistograms().run(input=[downloads.wait()], params=data_range)
    print_errors(histograms)

    db.create('histograms', histograms.wait())
    histograms.purge()

    metadata = PullMetadata().run(input=[downloads.wait()])
    print_errors(metadata)
    downloads.purge()

    db.create('metadata', metadata.wait())

    features = InvertFeatures().run(input=[metadata.wait()])
    print_errors(features)
    metadata.purge()

    db.create('features', features.wait())

    top = TopDownloads().run(input=[features.wait()])
    print_errors(top)
    
    db.create('top-new', top.wait())
    top.purge()

    summaries = PrecalculateSummaries().run(input=[features.wait()])
    print_errors(summaries)
    features.purge()

    db.create('summaries-new', summaries.wait())
    summaries.purge()
Example #28
0
def create_simple():
	posted = flask.request.form
	table_name = abbrev(posted['table name'])

	new_value = {}
	for key in posted.keys():
		if key.startswith('table '): continue

		value = posted[key]
		if value.startswith('http'): value = url(value)
		else: value = text(posted[key])

		if value == '': continue

		if '-' in key: key = '`%s`' % key
		new_value[key] = value

	try:
		db.create(table_name, values = new_value, credentials = auth.credentials)

	except db.UnauthorizedAccessException, message:
		return auth.authenticate(message)
Example #29
0
def postProduto():

    dados = request.get_json(force=True)

    if dados['descricao'] != '':

        cur = conn.cursor()

        if db.create(dados, cur):

            db.applyCommit(conn)

            return jsonify(db.getAll(cur)), 201
        #end if
    #end if
    return jsonify({"message": "Erro. Operação inválida."})
Example #30
0
def cabinetadd():
    if request.method == 'GET':
        idc_columns = [
            'id', 'name', 'address', 'adminer', 'phone', 'cabinet_num',
            'switch_num'
        ]
        idcs = db.get_list(idc_columns, 'idc')
        idcinfo = []
        for idc in idcs:
            idcinfo.append({'id': idc['id'], 'name': idc['name']})
        return render_template('assets/cabinet/cabinetadd.html',
                               idcinfo=idcinfo,
                               display=dis)
    else:
        data = request.form.to_dict()
        util.WriteLog('infoLogger').warning(
            '%s add cabinet %s' % (session['username'], data['name']))
        return json.dumps(db.create(data, 'cabinet'))
Example #31
0
def send_message():
    try:
        db = create()
        cur = db.cursor()
        sql = '''select * from main.message_to_send where time_to_send <= datetime('now', 'localtime') and status = 0'''
        cur.execute(sql)
        rows = cur.fetchall()
        for row in rows:
            print 'sending %s' % row['message_text']
            bot.sendMessage(chat_id="@enscp", text=row['message_text'])
        sql_update = '''update main.message_to_send 
                           set status = 1 
                         where time_to_send <= datetime('now', 'localtime') and status = 0'''
        cur.execute(sql_update)
        cur.close()
        db.commit()
        db.close()
    except Exception as ex:
        print ex.message
Example #32
0
def signup():
    error = {}
    if request.method == "POST":
        flg = create(request.form)
        if flg["passwordError"]:
            mess = "Your password must be at least 8 characters."
        else:
            mess = None
        error["password"] = mess
        if flg["usernameError"]:
            mess = "This username is already used."
        else:
            mess = None
        error["username"] = mess
        if flg["againError"]:
            mess = "Passwords must match."
        else:
            mess = None
        error["again"] = mess
        if len(filter(lambda x: type(x) is str, error.values())) == 0:
            session["username"] = request.form["username"]
            return redirect("/")
    return render_template("signup.html", error=error)
Example #33
0
def drop():
    ''' Test file and save it to database '''
    user = check_user()  #
    if type(user) == dict:
        return jsonify(user)

    requires = ["filename", "filetext", "row", "col"]  # #
    failed = bad_request(requires)
    if failed is not None:
        return jsonify(failed)

    if user.form == 'ghost':  # # #
        return jsonify({"msg": "you're a ghost", "error": True})

    filename = request.json['filename']
    text = request.json['filetext']
    row = request.json['row']
    col = request.json['col']

    user.material += 1
    file_obj = create_file(filename, text, row, col)
    result = nest.test_file(file_obj)
    material = result['material']
    script = db.create("Script",
                       user_id=user.id,
                       material=material,
                       filename=filename,
                       filetext=text,
                       filetype=file_obj['filetype'],
                       row=row,
                       col=col,
                       location=user.location)
    result['script'] = return_script(user, script)
    user.touch()
    db.save()
    # # # #
    return jsonify({"result": result, "user": return_user(user)})
Example #34
0
def drop():
    ''' Test file and save it to database '''
    user_ip = request.remote_addr
    user = db.get_user_by_ip(user_ip) 
    if user is None:
        return jsonify({"msg": "ip not set"}), 401
    user.touch()

    requires = ["filename", "filetext", "row", "col"];
    if not request.json:
        return jsonify({"msg": "not json"}), 400
    for req in requires:
        if not request.json.get(req):
            return jsonify({"msg": "no {}".format(req)}), 400

    filename = request.json['filename']
    text = request.json['filetext']
    row = request.json['row']
    col = request.json['col']
    
    if user.form == 'ghost':
        return jsonify({"msg": "you're a ghost"})

    user.material += 1;
    file_obj = create_file(user_ip, filename, text, row, col)
    material = nest.test_file(file_obj)
    
    new_file = db.create("Script", user_id=user.id, material=material,
              filename=filename, filetext=text, filetype=file_obj['filetype'],
              row=row, col=col, location=user.location)
    db.save()
    res = user.to_dict()
    del res['ip']
    script = new_file.to_dict()
    script['user'] = res
    return jsonify({"script" : script, "user": res})
Example #35
0
def handle(msg):
    team = Team()
    con = create()
    reply_to_message_id = msg['message_id']
    chat_id = msg["chat"]["id"]
    team_name = team.get_team_by_chat(chat_id)
    message_text = '%s' % msg['text'].encode("utf-8")
    print message_text
    if message_text == '/ping':
        bot.sendMessage(chat_id,
                        "I'm alive!",
                        reply_to_message_id=reply_to_message_id)
        return
    if team_name is None:
        try:
            team_name = team.register_chat_to_team(chat_id,
                                                   str(message_text).upper())
            bot.sendMessage(chat_id,
                            "Вы зарегистрировались в команду %s" % team_name)
            return
        except TeamError as ex:
            bot.sendMessage(chat_id, ex.msg)
            return
    print team
    task_id = team.get_team_task_id(team_name)
    if task_id == 1:
        if message_text == '/pleasestartstudy':
            team.set_team_task_id(team_name, 2)
            #scheduler.start()
            searcher = Searcher(con, team_name)
            task_id = task_id + 1
            scheduler.add_job(func=lambda: study_job(chat_id, searcher),
                              trigger=IntervalTrigger(seconds=10),
                              id='db_info',
                              name='Fill db info',
                              replace_existing=True)
Example #36
0
from conf import DB_CONFIG
from db import create
from sqlalchemy import Column, Integer, String, ForeignKey, Enum
from sqlalchemy.orm import relationship, backref
from sqlalchemy.ext.declarative import declarative_base

Base, engine = create(DB_CONFIG)

class bc10_clients(Base):
    __tablename__ = 'bc10_clients'
    __table_args__ = {'autoload': True}
    oasis = relationship('bc10_oasis', backref='bc10_oasis', lazy='dynamic')

    @property
    def serialize(self):
        return {
            'client_id': self.client_id,
            'name': self.name
        }

class bc10_transactions(Base):
    __tablename__ = 'bc10_transactions'
    __table_args__ = {'autoload': True}

    @property
    def serialize(self):
        return {
           # 'from': self.from,
           'id': self.id,
           'client_id': self.client_id,
           'content': self.content,
Example #37
0
    rg.chat('-1d', '24 uur')
    rg.chat('-1w', '1 week')
    rg.chat('-1m', '1 maand')
    rg.members('-1d', '24 uur')
    rg.posts('-1d', '24 uur')
    rg.topics('-1d', '24 uur')
    rg.visitors('-1d', '24 uur')
    rg.visitors('-1w', '1 week')
    rg.visitors('-1m', '1 maand')


def log(message):
    l = open(datadir + "update.log", "a")
    l.write(datetime.datetime.now().strftime("%b %d %H:%M:%S") + " " + str(message) + "\n")
    l.close()

try:
    open(rrd_file)
except:
    log("The Round Robin Database does not yet exist, so we're going to create it first.")
    try:
        db.create()
    except rrdtool.error as e:
        log("It didn't work out, because %s. Exiting now!" % e)
        exit(1)
try:
    update()
except:
    log("Updating failed :<")
    exit(1)
Example #38
0
 def setUp(self):
     db.create()
Example #39
0
		'location':  (int,  'location'),
	}

	try:
		for (name, (type_converter, field_name)) in fields.items():
			if not name in posted or len(posted[name]) == 0:
				new_value[field_name] = None
				continue

			new_value[field_name] = str(type_converter(posted[name]))

	except ValueError, e:
		flask.abort(400, e)

	try:
		db.create('ConferenceInstances', values = new_value,
				credentials = auth.credentials)

	except db.UnauthorizedAccessException, message:
		return auth.authenticate(message)

	return flask.redirect('/edit/conference/%s' % posted['abbreviation'])


@app.route('/edit/conference/update_event', methods = [ 'POST' ])
@auth.requires_auth
def update_event():
	new_value = {}
	posted = flask.request.form

	# POST form -> SQL mapping
	fields = {
Example #40
0
        entry = client.info(svnSavePath)
        svnLastVersion = entry.commit_revision.number
        if os.path.exists(svnExportPath):
            # os.rmdir(svnSavePath) #只能删除空目录
            # os.removedirs(svnSavePath)
            shutil.rmtree(svnExportPath)
        client.export(svnurl, svnExportPath)
        data = dict({'version': svnLastVersion, 'introduction': info['introduction'], 'username': info['username'], 'date': date})

        # 需将此机器的公钥拷到tools.uc.ppweb.com.cn
        cmd = 'rsync -avzLPq --delete %s/* [email protected]:/data/oop/cmdb' % svnExportPath
        try:
            subprocess.check_call(cmd, shell=True)
            paramiko_command('tools.uc.ppweb.com.cn', 'cd /data/oop;bash run.sh')
            paramiko_command('tools.uc.ppweb.com.cn', "sed -i '/代码发布/d' /data/oop/cmdb/app/templates/base.html")
            db.create(data, 'codePublish')
        except Exception,e:
            print e
            return json.dumps({'code':1, 'errmsg': '代码发布失败:rsync传输失败'})

        return json.dumps({'code':0})


@app.route('/roolBack/', methods=['POST'])
@login_required
def roolBack():
    verId = request.form.get('verId')
    columns = ['version']
    where = 'id=%s' % verId
    version = json.loads(db.get_one(columns, where, 'codePublish'))['version']
    client = pysvn.Client()
Example #41
0
def stat_data_import(params):
    platform = params['platform']
    serverid = params['serverid']
    qufu_columns = ['qufu']
    date = params['date'].split(' ')[0]
    where = 'platform=' + platform + ' and ' + 'serverid=' + serverid
    try:
        qufu = json.loads(db.get_one(qufu_columns, where, 'virtuals'))['qufu']
    except Exception as e:
        print e
    columns_day = ['qufu','platform','serverid','data_date','new_reg_user_num','login_user_num','user_login_num',
                   'pay_user_num','pay_num','pay_user_ARPU','avg_online','mountain_online','avg_online_ARPU',
                   'login_user_pay_trans_rate','new_reg_user_pay_transe_rate','pay_money','new_pay_user_num','pay_m_pt','pay_m_gw']
    columns_total = ['qufu','platform','serverid','data_date','new_reg_user_num','login_user_num','user_login_num',
                     'pay_user_num','pay_num','pay_user_ARPU','mountain_online','login_user_pay_trans_rate','total_reg_user_pay_transe_rate','pay_money']
    value_day = []
    for x in qufu,platform,serverid,date:
        value_day.append(x)
    for y in params['data_day']:
        value_day.append(y)
    for z in params['data_day_duizhang']:
        value_day.append(z)
    data=dict(zip(columns_day, value_day))
    data['pay_user_ARPU'] = round(data['pay_user_ARPU'], 2)
    data['avg_online'] = round(data['avg_online'], 2)
    data['avg_online_ARPU'] = round(data['avg_online_ARPU'], 2)
    data['login_user_pay_trans_rate'] = round(data['login_user_pay_trans_rate'], 2)
    data['new_reg_user_pay_transe_rate'] = round(data['new_reg_user_pay_transe_rate'], 2)
    where1 =  'platform=' + platform + ' and ' + 'serverid=' + serverid + ' and ' + "data_date='%s'" % date
    result = db.get_one(columns_day, where1, 'data_day', list=True)
    if len(result) > 0:
        db.update(data, where1, 'data_day')
    else:
        db.create(data, 'data_day')


    value_week = []
    for x in qufu,platform,serverid,date:
        value_week.append(x)
    for y in params['data_week']:
        value_week.append(y)
    columns_week = columns_day[:-2]
    data=dict(zip(columns_week, value_week))
    data['pay_user_ARPU'] = round(data['pay_user_ARPU'], 2)
    data['avg_online'] = round(data['avg_online'], 2)
    data['avg_online_ARPU'] = round(data['avg_online_ARPU'], 2)
    data['login_user_pay_trans_rate'] = round(data['login_user_pay_trans_rate'], 2)
    data['new_reg_user_pay_transe_rate'] = round(data['new_reg_user_pay_transe_rate'], 2)
    where1 =  'platform=' + platform + ' and ' + 'serverid=' + serverid + ' and ' + "data_date='%s'" % date
    result = db.get_one(columns_week, where1, 'data_week', list=True)
    if len(result) > 0:
        db.update(data, where1, 'data_week')
    else:
        db.create(data, 'data_week')


    value_month = []
    for x in qufu,platform,serverid,date:
        value_month.append(x)
    for y in params['data_month']:
        value_month.append(y)
    for z in params['data_month_duizhang']:
        value_month.append(z)
    data=dict(zip(columns_day, value_month))
    data['pay_user_ARPU'] = round(data['pay_user_ARPU'], 2)
    data['avg_online'] = round(data['avg_online'], 2)
    data['avg_online_ARPU'] = round(data['avg_online_ARPU'], 2)
    data['login_user_pay_trans_rate'] = round(data['login_user_pay_trans_rate'], 2)
    data['new_reg_user_pay_transe_rate'] = round(data['new_reg_user_pay_transe_rate'], 2)
    where1 =  'platform=' + platform + ' and ' + 'serverid=' + serverid + ' and ' + "data_date='%s'" % date
    result = db.get_one(columns_day, where1, 'data_month', list=True)
    if len(result) > 0:
        db.update(data, where1, 'data_month')
    else:
        db.create(data, 'data_month')


    value_total = []
    for x in qufu,platform,serverid,date:
        value_total.append(x)
    for y in params['data_totol']:
        value_total.append(y)
    data=dict(zip(columns_total, value_total))
    data['pay_user_ARPU'] = round(data['pay_user_ARPU'], 2)
    data['login_user_pay_trans_rate'] = round(data['login_user_pay_trans_rate'], 2)
    data['total_reg_user_pay_transe_rate'] = round(data['total_reg_user_pay_transe_rate'], 2)
    where1 =  'platform=' + platform + ' and ' + 'serverid=' + serverid + ' and ' + "data_date='%s'" % date
    result = db.get_one(columns_total, where1, 'data_total', list=True)
    if len(result) > 0:
        db.update(data, where1, 'data_total')
    else:
        db.create(data, 'data_total')
Example #42
0
 def _save(self, data_dict):
     context = {}
     data_dict['connection_url'] = self.postgres_url
     db.create(context, data_dict)
Example #43
0
def stat_import(params):

    frame_key = ('ptname','date','frame_49','frame_55','frame_60','frame_49_new','frame_55_new','frame_60_new')
    caton_key = ('ptname','date','caton_5','caton_15','caton_30','caton_50','caton_70','caton_95','caton_100','caton_5_new','caton_15_new','caton_30_new',
                 'caton_50_new','caton_70_new','caton_95_new','caton_100_new')
    load_key = ('ptname','date','load_config','load_res')
    mem_key = ('ptname','date','memory_500','memory_700','memory_900','memory_1100')
    mouse_key = ('ptname','date','mouse_20','mouse_30','mouse_50','mouse_75','mouse_20_new','mouse_30_new','mouse_50_new','mouse_75_new')
    enter_battle_key = ('ptname','date','success','battle_res_load','army_success','room_success','lobby_success','frist_root_success','frist_lobby_success',
                        'frist_battle_success','fighting_drop','frist_fighting_drop','ladder_drop','frist_ladder_drop','trans_drop','browser','ladder_match')

    for frame in params['4399frame'],params['7k7kframe']:
        db.create(dict(zip(frame_key,frame)),'battle_frame_rate')

    for caton in params['4399caton'],params['7k7kcaton']:
        db.create(dict(zip(caton_key,caton)),'game_kadun')

    for load in params['4399load'],params['7k7kload']:
        db.create(dict(zip(load_key,load)),'game_load')

    for mouse in params['4399mouse'],params['7k7kmouse']:
        db.create(dict(zip(mouse_key,mouse)),'game_mouse')

    for mem in params['4399memory'],params['7k7kmemory']:
        db.create(dict(zip(mem_key,mem)),'game_mem')

    for enter_battle in params['4399enter'],params['7k7kenter']:
        db.create(dict(zip(enter_battle_key,enter_battle)),'enter_battle')
Example #44
0
	def configure(self):
		r = requests.get( telegram_bot_url + telegram_token + "/setWebhook", params={'url': heroku_url} )
		create()
		current_date = time.time()
		insert_digest_date(current_date)
Example #45
0
def color_gen(name):
    #generates random color based on name
    c = hex(hash(name))
    if len(c) < 8:
        return '#'+c[2:]+'f'*(8-len(c))
    return '#' + c[-6:]

##
## Performed Every Restart
##
     
# connect to database and generate it
conn = sqlite3.connect('ratings.db')
conn.row_factory = sqlite3.Row
db.create(conn)

# read template files
templates = {}
with open('templates/main.html') as f:
    templates['main'] = unicode(f.read())
with open('templates/index.html') as f:
    templates['index'] = unicode(f.read())
with open('templates/movie_full.html') as f:
    templates['movie_full'] = unicode(f.read())
with open('templates/movie_brief.html') as f:
    templates['movie_brief'] = unicode(f.read())
with open('templates/movie_slim.html') as f:
    templates['movie_slim'] = unicode(f.read())
with open('templates/reviewer_full.html') as f:
    templates['reviewer_full'] = unicode(f.read())
Example #46
0
import preprocessing
import processing
import db

consumer_key = 'YRnp0q7lSJLRU1KFzXzfQpgBj'
consumer_secret = '1GrTLHR67JMjqh1jzeHzfZEwesEGTI8WMkH5IlrvEKzw5VKXWl'
access_token = '157119280-8DPkm3KENaA7rrBbhk52PizQL8gKIGnS4q1crk5o'
access_token_secret = 'v6XmeY9PwfyIBf85dvud31e3GfJCM5VaaqnmTL7nhhONx'

oauth = tweepy.OAuthHandler(consumer_key, consumer_secret)
oauth.set_access_token(access_token, access_token_secret)

api = tweepy.API(oauth)

db.connect()
db.create()

last_id = {'#syriza': 0, '#neadimokratia': 0, '@tsipras': 0, '@mitsotakis': 0}
loops = 0

schedule = sched.scheduler(time.time, time.sleep)


def get_tweets():
    global last_id, loops
    print("Let's collect some tweets!")
    tweets = {
        'id': [],
        'text': [],
        'clean_text': [],
        'category': [],
Example #47
0
        print('Refrence File not Found')
        quit()

    refrence_ws = refrence_wb.active
    max_row = refrence_ws.max_row - 1
    tmp = sp.call('clear', shell=True)  # Clear screen

    for i in range(max_row):
        row = i + 2
        school = refrence_ws['A' +
                             str(row)].value  # Get information for each thread
        year = refrence_ws['B' + str(row)].value
        print(school, year, i + 1, '/', max_row)
        if refrence_ws['C' + str(row)].value is not None:  # If there is a link
            try:
                db.create(refrence_ws['C' + str(row)].value, sys.argv[2],
                          school, year, 'ED')
            except IndexError:  # Don't remember why this is here, but it accounts for some error
                continue
        if refrence_ws['D' + str(row)].value is not None:
            try:
                db.create(refrence_ws['D' + str(row)].value, sys.argv[2],
                          school, year, 'RD')
            except IndexError:
                continue
        tmp = sp.call('clear', shell=True)
    wb = load_workbook(sys.argv[2])  # Run formatting on completed workbook
    wb = db.clean(wb)
    db.parse_sat1(wb)
    db.parse_act(wb)
    db.create_additional_entries(wb)
    wb.save(sys.argv[2])
Example #48
0
def create():
    #  id + data
    return db.create()