def _push_config(self): self.run_javascript("$('#arch').html('%s')" % self._config.arch) self.run_javascript( "$('#autostart').toggleClass('icon-check', %s).toggleClass(\ 'icon-check-empty', %s)" % (to_json( self._config.autostart), to_json(not self._config.autostart))) if self._config.live: self.run_javascript("$('#install').toggleClass('hide', false);") self.run_javascript( "$('#install-cli').toggleClass('hide', false);") else: self.run_javascript("$('#build').toggleClass('hide', false);") self.run_javascript("$('#donate').toggleClass('hide', false);")
def _push_config(self): self.run_javascript("$('#arch').html('%s')" % self._config.arch) self.run_javascript( "$('#autostart').toggleClass('icon-check', %s).toggleClass(\ 'icon-check-empty', %s)" % (to_json(self._config.autostart), to_json(not self._config.autostart))) if self._config.live: self.run_javascript("$('#install').toggleClass('hide', false);") self.run_javascript( "$('#install-cli').toggleClass('hide', false);") else: self.run_javascript("$('#build').toggleClass('hide', false);") self.run_javascript("$('#donate').toggleClass('hide', false);")
def keyword_combinations(): keywords = parse_keywords(request.args["k"]) combos = [list(combinations(keywords, i)) for i in xrange(len(keywords), 1, -1)] ret = to_json([item for sublist in combos for item in sublist]) return Response(response=ret, status=200, mimetype="application/json")
def main(): start_gtk_thread() # Create a proper file:// URL pointing to demo.xhtml: file = os.path.abspath('demo.xhtml') uri = 'file://' + urllib.pathname2url(file) browser, web_recv, web_send = \ synchronous_gtk_message(launch_browser)(uri, quit_function=Global.set_quit) # Finally, here is our personalized main loop, 100% friendly # with "select" (although I am not using select here)!: last_second = time.time() uptime_seconds = 1 clicks = 0 while not Global.quit: current_time = time.time() again = False msg = web_recv() if msg: msg = from_json(msg) again = True if msg == "got-a-click": clicks += 1 web_send('document.getElementById("messages").innerHTML = %s' % to_json('%d clicks so far' % clicks)) # If you are using jQuery, you can do this instead: # web_send('$("#messages").text(%s)' % # to_json('%d clicks so far' % clicks)) if current_time - last_second >= 1.0: web_send('document.getElementById("uptime-value").innerHTML = %s' % to_json('%d' % uptime_seconds)) # If you are using jQuery, you can do this instead: # web_send('$("#uptime-value").text(%s)' # % to_json('%d' % uptime_seconds)) uptime_seconds += 1 last_second += 1.0 if again: pass else: time.sleep(0.1)
def save_to_db(all_sets_json, keyword_id): formated_json = [(x["id"], to_json(x)) for x in to_object(all_sets_json)] cursor = get_cursor() for quizlet_id, json in formated_json: cursor.callproc( "create_or_update_quizlet", (quizlet_id, keyword_id, json)) cursor.connection.commit() cursor.close()
def update_user_deck(): try: json = request.args["json"] deck_id = request.args["deck_id"] cursor = get_cursor() cursor.execute( """UPDATE UserDecks SET json=%s WHERE deck_id=%s""", (json, deck_id)) user_deck_id = cursor.lastrowid cursor.connection.commit() cursor.close() return to_json(query_one("SELECT * FROM UserDecks WHERE deck_id = %s", user_deck_id)) except: return '{"error":"not saved"}'
def save_user_deck(): try: json = request.args["json"] google_id = request.args["google_id"] cursor = get_cursor() cursor.execute( "INSERT INTO UserDecks (google_id,json) VALUES (%s, %s)", (google_id, json)) user_deck_id = cursor.lastrowid cursor.connection.commit() cursor.close() return to_json(query_one("SELECT * FROM UserDecks WHERE deck_id = %s", user_deck_id)) except: return '{"error":"not saved"}'
def main(): start_gtk_thread() # Create a proper file:// URL pointing to demo.xhtml: file = os.path.abspath('ui.xhtml') uri = 'file://' + urllib.pathname2url(file) browser, web_recv, web_send = \ synchronous_gtk_message(launch_browser)(uri, quit_function=Global.set_quit) # Finally, here is our personalized main loop, 100% friendly # with "select" (although I am not using select here)!: last_second = time.time() uptime_seconds = 1 clicks = 0 i = 0 while not Global.quit: current_time = time.time() i = i + 1 temp = 30 + i rpm = i * 100 + 300 speed = i throttle_pos = i web_send('document.getElementById("temp").innerHTML = %s' % to_json('%d' % temp)) web_send('document.getElementById("rpm").innerHTML = %s' % to_json('%d' % rpm)) web_send('document.getElementById("speed").innerHTML = %s' % to_json('%d' % speed)) web_send('document.getElementById("throttle_pos").innerHTML = %s' % to_json('%d' % throttle_pos)) if (i >= 100): i = 0 time.sleep(.1)
def get_user_deck(google_id): try: return to_json(query_all("""SELECT deck_id, json FROM UserDecks WHERE google_id""", google_id)) except: return '{"error":"not found"}'
def main(): start_gtk_thread() langcard_db = LangcardDB(); # Create a proper file:// URL pointing to demo.xhtml: file = os.path.abspath('html/demo.xhtml') uri = 'file://' + urllib.pathname2url(file) browser, web_recv, web_send = \ synchronous_gtk_message(launch_browser)(uri, quit_function=Global.set_quit) # Finally, here is our personalized main loop, 100% friendly # with "select" (although I am not using select here)!: last_second = time.time() uptime_seconds = 1 clicks = 0 while not Global.quit: # GETLIST # SETPHRA # GETRAND current_time = time.time() again = False msg = web_recv() if msg: print msg if msg and msg[0:7]=="GETRAND": randomword_array = langcard_db.langcardGetRandomWord(); randonword_struct = {} randonword_struct['id'] = randomword_array[0]; randonword_struct['comments'] = randomword_array[1]; randonword_struct['original'] = randomword_array[2]; randonword_struct['translation'] = randomword_array[3]; randonword_struct['phrase'] = randomword_array[4]; randonword_struct['position'] = randomword_array[5]; randomword_json = to_json(randonword_struct) randomword_json = randomword_json.replace('\'','') print randomword_json web_send("setRandomWord('%s')" % (randomword_json)); continue; if msg and msg[0:7]=="SETPHRA": msg = from_json(msg[7:]) langcard_db.langcardSetPhrase(msg); again = True continue if msg and msg[0:7]=="GETLIST": phrases = langcard_db.langcardGetPhraseList() previd=-1 phraselist = {} for index in phrases: currentid=phrases[index][0] if (currentid!=previd): phrase = {} phrase['id'] = phrases[index][0] phrase['phrase'] = phrases[index][4] phrase['words'] = {} word = {} word['original'] = phrases[index][2]; word['translation'] = phrases[index][3]; word['comments'] = phrases[index][1]; word['position'] = phrases[index][5]; phrase['words'][len(phrase['words'])] = word; if (currentid!=previd): phraselist[len(phraselist)] = phrase previd=currentid; # phraselist[len(phraselist)] = phrase phraselist = to_json(phraselist) phraselist = phraselist.replace('\'','') web_send("setList('%s')" % (phraselist)); if again: pass else: time.sleep(0.1)
def get_decks(keyword): keyword_id, last_updated, created = get_or_create_keyword(keyword) if expired_keyword(last_updated) or created or not keyword_has_decks(keyword_id): create_decks_from_quizlet(keyword, keyword_id) return to_json(get_decks_from_database(keyword), use_decimal=True)
def capture_data(self): #Find supported sensors - by getting PIDs from OBD # its a string of binary 01010101010101 # 1 means the sensor is supported self.supp = self.port.sensor(0)[1] self.supportedSensorList = [] self.unsupportedSensorList = [] print "Supported!!!!! " print self.supp start_gtk_thread() # Create a proper file:// URL pointing to demo.xhtml: file = os.path.abspath('ui.xhtml') uri = 'file://' + urllib.pathname2url(file) browser, web_recv, web_send = \ synchronous_gtk_message(launch_browser)(uri, quit_function=Global.set_quit) # loop through PIDs binary #for i in range(0, len(self.supp)): for i in range(0, 32): print "INDEX " print i if self.supp[i] == "1": # store index of sensor and sensor object self.supportedSensorList.append([i+1, obd_sensors.SENSORS[i+1]]) else: self.unsupportedSensorList.append([i+1, obd_sensors.SENSORS[i+1]]) for supportedSensor in self.supportedSensorList: print "supported sensor index = " + str(supportedSensor[0]) + " " + str(supportedSensor[1].shortname) time.sleep(3) if(self.port is None): return None #Loop until Ctrl C is pressed try: #while True: while not Global.quit: localtime = datetime.now() current_time = str(localtime.hour)+":"+str(localtime.minute)+":"+str(localtime.second)+"."+str(localtime.microsecond) log_string = current_time + "\n" results = {} for supportedSensor in self.supportedSensorList: sensorIndex = supportedSensor[0] (name, value, unit) = self.port.sensor(sensorIndex) log_string += name + " = " + str(value) + " " + str(unit) + "\n" web_send('document.getElementById('+ "\"" + str(supportedSensor[1].shortname)+ "\"" ').innerHTML = %s' % to_json('%s' % str(value))) print log_string print "F**K" print name except KeyboardInterrupt: self.port.close() print("stopped")