def get_row(conn, cacheid): """ get a geocache from the database """ cacheid = cacheid.upper() ret = mysqlite.get_row(conn, cacheid) if ret is not None and ret[0] != "": g_arr = geocache.GeoCache() g_arr.cacheid = ret[0] g_arr.dltime = ret[1] g_arr.cachename = ret[2] g_arr.cacheowner = ret[3] g_arr.cacheurl = ret[4] g_arr.cachesize = ret[5] g_arr.cachetype = ret[6] g_arr.lat = ret[7] g_arr.lon = ret[8] g_arr.diff = ret[9] g_arr.terr = ret[10] g_arr.hidden = ret[11] g_arr.lastfound = ret[12] g_arr.short = ret[13] g_arr.body = htmlcode.cache_images(ret[14], SESSION) g_arr.hint = ret[15].replace("<br>", "\n") g_arr.found = ret[16] row = g_arr else: row = None return row
def save_logs(conn, cacheid, logstr, user_token): """ Save logs to the database """ cacheid = cacheid.upper() json_object = json.loads(logstr) page_info = json_object['pageInfo'] size = page_info['size'] total_rows = page_info['totalRows'] pages = math.ceil(total_rows / size) if pages > 5: pages = 5 json_array = json_object['data'] for i in range(1, pages + 1): if i > 1: json_array = get_more_logs(i, size, user_token) if json_array is None: return for log in json_array: l_b = logbook.LogBook() l_b.cacheid = cacheid l_b.logid = log['LogID'] l_b.accountid = log['AccountID'] l_b.logtype = log['LogType'] l_b.logimage = log['LogTypeImage'] l_b.logtext = htmlcode.cache_images(log['LogText'], SESSION) l_b.created = clean_up(log['Created']) l_b.visited = clean_up(log['Visited']) save_log(conn, l_b) user = users.Users() user.accountid = log['AccountID'] user.username = log['UserName'] user.accountguid = log['AccountGuid'] user.avatarimage = log['AvatarImage'] user.findcount = log['GeocacheFindCount'] user.hidecount = log['GeocacheHideCount'] save_user(conn, user) for img in log['Images']: image = images.Images() image.cacheid = cacheid image.accountid = log['AccountID'] image.imageid = img['ImageID'] image.logid = log['LogID'] image.filename = img['FileName'] image.created = clean_up(img['Created']) image.name = img['Name'] image.descr = img['Descr'] save_image(conn, image)
def get_logs(conn, cacheid): """ get logs from db """ cacheid = cacheid.upper() cursor = conn.cursor() cursor.execute( "SELECT * FROM logbook, users where logbook.accountid = users.accountid and " + "cacheid = ? ORDER BY logid DESC", (cacheid, )) g_arr = "[" for row in cursor: output = {} output['cacheid'] = row[0] output['logid'] = row[1] output['accountid'] = row[2] output['logtype'] = row[3] output['logimage'] = row[4] output['logtext'] = htmlcode.cache_images(row[5], SESSION) output['created'] = datetime.datetime.fromtimestamp( row[6]).strftime('%Y-%m-%d') output['visited'] = datetime.datetime.fromtimestamp( row[7]).strftime('%Y-%m-%d') output['accountid'] = row[8] output['username'] = row[9] output['accountguid'] = row[10] output['avatarimage'] = row[11] output['findcount'] = row[12] output['hidecount'] = row[13] output['images'] = get_images(conn, row[1]) g_arr += json.dumps(output) + "," cursor.close() close_db(conn) if g_arr[-1:] == ",": g_arr = g_arr[:-1] g_arr += "]" return g_arr
def get_log(conn, logid): """ Get a logbook entry """ cursor = conn.cursor() cursor.execute("SELECT * from logbook where logid = ?", (logid, )) ret = cursor.fetchone() cursor.close() if ret is not None and ret[0] != "": l_b = logbook.LogBook() l_b.cacheid = ret[0] l_b.logid = ret[1] l_b.accountid = ret[2] l_b.logtype = ret[3] l_b.logimage = ret[4] l_b.logtext = htmlcode.cache_images(ret[5], SESSION) l_b.created = ret[6] l_b.visited = ret[7] row = l_b else: row = None return row