def prepare(): usernames = load_users() ids = get_ids() users = {} for id in ids: user = load_user(id) users[id] = user res = set() i = 0 for id, user in users.items(): i += 1 print i for pid in user.get('pros', []): pid = int(pid) puser = users.get(pid) #nms = [usernames.get(id), usernames.get(pid)] #if nms[0] and nms[1]: #res.add(tuple(nms)) if puser: if unicode(id) in puser.get('pros', []): nms = [usernames[id], usernames[pid]] nms.sort() res.add(tuple(nms)) res = list(res) return res
def main(): # Starting Log object. Saves a log after execution in logs/ print("Starting competitions module.") log = Log(PATH, 'competition') try: # Getting new competitions from WCA's API print("Reading new competitions.") actual = get_new_competitions(LINK_API, PATH) log.actual = len(actual) print("Found %d competitions at WCA" % len(actual)) # Getting competitions from files/competitions.json print("Reading old competitions.") old = load_competitions(PATH) log.old = len(old) print("Found %d competitions at json" % len(old)) # Comparing to get which competition was just announced print("Comparing both...") new = compare_competitions(old, actual) log.new = len(new) print("Found %d new competitions" % len(new)) if len(new) != 0: # Loading users and starting reddit, and then sending. print("Loading users.") users = load_users(PATH) print("Starting reddit.") reddit = get_reddit_credentials(PATH) print("Matching competitions...") match_competitions_users(new, users, SEND_FLAG, SIGNATURE, reddit) # updating competitions on files/competitions.json print("Saving competitions.json file.") save_competitions(actual, PATH) # saving log log.update_resume(new_competitions=len(new), total_competitions=len(actual)) log.save('success') except Exception as e: print("Exception occurred: ", e) log.error(e) log.save('error') print("Done!") return
def settings(path, params, env): allusers = users.load_users() user = __get_user(env, allusers) userid = str(user["sina_id"]) if user: print "authorized" # authorized try: request_body_size = int(env.get("CONTENT_LENGTH", 0)) except (ValueError): request_body_size = 0 if request_body_size: # save settings request_body = env["wsgi.input"].read(request_body_size) d = parse_qs(request_body) allusers[userid]["twitter_name"] = twitter_name = d["twitter_name"][0] allusers[userid]["activated"] = d.get("activated") and True or False allusers[userid]["ignore_tag"] = d.get("ignore_tag", [""])[0] allusers[userid]["no_trunc"] = not d.get("keep_original") allusers[userid]["rasterize"] = d.get("rasterize") and True or False users.save_users(allusers) # redirect to synced status = "302 Found" headers = [ ("Content-Type", "text/plain"), ("Location", "/synced"), ("Set-Cookie", "twitter_name=%s" % twitter_name), ] content = "" else: # render settings status = "200 OK" headers = [("Content-Type", "text/html;charset=UTF-8")] user["activated_checked"] = user["activated"] and 'checked="1"' or "" user["userinfo"] = __render_userinfo(user) user["ignore_tag"] = user["ignore_tag"].replace('"', """) user["keep_original"] = (not user.get("no_trunc", True)) and 'checked="1"' or "" user["rasterize_checked"] = user.get("rasterize") and 'checked="1"' or "" content = __template(dirname + "/settings.html", user).encode("utf-8") else: # unauthorized logger.info("unauthorized") status = "302 Found" headers = [("Content-Type", "text/plain"), ("Location", "/")] content = "" return (status, headers, content)
#! /usr/bin/env python """ @author: dell """ import users users.load_users('data/users.pkl') import words words.load_words('data/words.pkl') from collections import defaultdict def indicator(cat_id, dim): v = [0] * dim if cat_id >= 0: v[cat_id] = 1 return v def binary(w): if w == -1: return 0 if w == 0: return -1 if w == 1: return 1 def represent(example): vector = [] artist_id = example['artist'] track_id = example['track']
''' Created on Nov 9, 2014 @author: Jinali Jhaveri ''' import users users.load_users('data_pkl/users.pkl') import words words.load_words('data_pkl/words.pkl') from collections import defaultdict def indicator(cat_id, dim): v = [0] * dim if cat_id >= 0: v[cat_id] = 1 return v def binary(w): if w == -1: return 0 if w == 0: return -1 if w == 1: return 1 def represent(example): vector = [] artist_id = example['artist']
print("Loading Ratings & Movies") tableHandler.load_tables() # load other tables print("Generating Collaborative Filtering") collaborativeFiltering.generate_tables() # generate new tables print("Generating Matrix Factorisation") matrixFactorisation.generate_tables() # generate new tables ############### INITIALISATION ############### app = Flask(__name__) # initialise app app.secret_key = urandom(24) # generate secret key for session handling print("Loading Users") users.load_users() # load the users database from csv setUpTables() # loads tables print("=== Ready ===") ############### ROUTING ############### # all GET requests for pages should go through here @app.route('/', methods = ['GET']) def index(): if 'username' in session: # check if user logged in or not username = session['username'] return render_template('index.html', user = username) # return rendered index.html page else:
def index(path, params, env): allusers = users.load_users() user = __get_user(env, allusers) content = __template(dirname + "/index.html", {"userinfo": __render_userinfo(user)}) return ("200 OK", [("Content-Type", "text/html;charset=UTF-8")], content.encode("utf-8"))
#encoding: utf-8 import users print(users.path) print(users.user_info_tpl) print(users.load_users(users.path))