def get_all_lang(): term = request.args['term'] connection = oursql.Connection(conf.DBHOST[0], conf.DBUSRNAME[0], conf.DBPASSWD[0], db=conf.DBNAME[0]) cursor = connection.cursor(oursql.DictCursor) cursor.execute('select * from `languages` as l where l.name like ?', (term + '%', )) r = cursor.fetchall() connection.close() d = {} d['return'] = r response = jsonify(d) response.headers['Access-Control-Allow-Origin'] = '*' return response
def get_loc(): term = request.args['term'] connection = oursql.Connection(conf.DBHOST[0], conf.DBUSRNAME[0], conf.DBPASSWD[0], db=conf.DBNAME[0]) cursor = connection.cursor(oursql.DictCursor) cursor.execute( 'select l.name, c.country_name from `location` as l, `codes` as c where l.name like ? and l.code=c.code limit ?', (term + '%', 5)) r = cursor.fetchall() connection.close() d = {} d['return'] = r response = jsonify(d) response.headers['Access-Control-Allow-Origin'] = '*' return response
def connect_oursql(db, user, passwd, host='localhost', **args): import oursql orm.driver = 'oursql' orm.__connection = oursql.Connection(host, user, passwd, db=db, default_cursor=oursql.DictCursor, **args)
template = """ <p> <strong>This public document was automatically mirrored from <a href="https://pdf.yt/">PDFy</a>.</strong> </p> <ul> <li><strong>Original filename:</strong> %(real_filename)s</li> <li><strong>URL:</strong> <a href="http://pdf.yt/d/%(slug)s">https://pdf.yt/d/%(slug)s</a></li> <li><strong>Upload date:</strong> %(upload_date)s</li> </ul> """.replace("\n", "") with open("config.json", "r") as f: conf = json.loads(f.read()) dbconn = oursql.Connection(host=conf["database"]["hostname"], user=conf["database"]["username"], passwd=conf["database"]["password"], db=conf["database"]["database"], autoreconnect=True) cur = dbconn.cursor() cur.execute("SELECT `Id`, `SlugId`, `Filename`, `Uploaded`, `OriginalFilename` FROM documents WHERE `Mirrored` = 0 AND `Public` = 1") items = cur.fetchall() for doc in items: id_, slug, storage_filename, upload_date, real_filename = doc if upload_date is None: upload_date = "Before April 27, 2014" else: upload_date = upload_date.strftime("%B %d, %Y %H:%M:%S") source_file = "storage/%s" % storage_filename