def main(connection): gcm_service = gcm.GCM(options.gcm_key) descriptions = ExtraDataSets.getDatasetsDescriptions() for description in descriptions.values(): predictionsToRate = '' print(description) if not debug: predictionsToRate = lib.db_datasets.getDatasetDuePredictions(description.title, description.predictionFields, 10, connection) #Change number to rate to a more dynamic value else: predictionsToRate = lib.db_datasets.getDatasetDuePredictionsDemo(description.title, description.predictionFields, 10, connection) #Change number to rate to a more dynamic value print(predictionsToRate, sep='\n') for prediction in predictionsToRate: judgement = description.getJudgement(prediction) print(judgement) if judgement: regids = [] message = {"message" : "Your prediction have been judged", "link": r"https://" + options.hostname + r"/" + r"prediction/" + description.title + r"/" + prediction['url'], } print("notification: ", message) judgement["result"] = 1 lib.db_datasets.updateDatasetPredictionJudgement(description.title, prediction['id'], judgement, connection) wagers = lib.db_datasets.getDatasetWagersLocal(description.title, description.wagerFields, prediction['id'], connection) for wager in wagers: isRight = description.decideJudgement(wager, judgement) wager['wagerResult'] = isRight print(wager) if wager['regid']: regids.append(wager['regid']) lib.db_datasets.updateDatasetWagerJudgement(description.title, wager['authorID'], wager['predictionID'],wager['wagerResult'], connection) try: gcm_service.json_request(registration_ids=regids, data = message, priority='high') except Exception: print('regid was not found') pass connection.commit()
# (r"/register", RegisterAppClient), # (r"/prediction/twitter", AddTwitterPrediction), # (r"/prediction/twitter/wager/(.*)", AddTwitterPredictionWager), # (r"/prediction/twitter/comment/(.*)", AddTwitterPredictionComment), # (r"/prediction/twitter/(.*)", ShowTwitterPrediction), # (r"/user/withwagers/(.*)", ShowUserProfileWithWagers), # (r"/user/onlyundecided/(.*)", ShowUserProfileOnlyUndecided), # (r"/user/(.*)", ShowUserProfile), # (r"/confirm/twitter/ask", TwitterConfirms.AskTwitterPrediction), # (r"/confirm/twitter/confirm", TwitterConfirms.ConfirmTwitterPrediction), # (r"(.*)", MainHandler), #(r"/testPost/(.*)", TwitterTestPoster), # ]+ExtraDataSets.endpoints,**settings) if __name__ == "__main__": lib.util.parse_config_file("config.conf") server = options.mysql["server"] user = options.mysql["user"] password = options.mysql["password"] database = options.mysql["database"] conn = pymysql.connect(host=server, user=user, password=password, db=database,cursorclass=pymysql.cursors.DictCursor, charset='utf8') conn = lib.util.makePwnedConnection(conn) define("connection", conn) gcm = GCM(options.gcm_key) define("gcm", gcm) ExtraDataSets.init() app = make_app(options.as_dict()) app.listen(8080) tornado.ioloop.IOLoop.current().start()