def translate(): if not request.json: abort(400) else: req = request.json if not 'chatId' in req or not 'for' in req or not 'message' in req: abort(400) else: try: gs = goslate.Goslate() chatObj = Firebase('https://vivid-inferno-6896.firebaseio.com/' + req['chatId']) language1 = chatObj.child("language1").get() language2 = chatObj.child("language2").get() translatedText = "" if req['for'] == 1: print language1 # translatedText = gs.translate(req['message'], language1) r = requests.post(microsoftAuthUrl, data=payload) resJSON = r.json() accessToken = resJSON["access_token"] translationParams = {"text":req['message'], "from":language2, "to":language1} translationUrl = "http://api.microsofttranslator.com/v2/Http.svc/Translate?" + urllib.urlencode(translationParams) translationHeader = {'Authorization': "Bearer " + accessToken} r = requests.get(translationUrl, headers=translationHeader) print r.status_code print r.text elif req['for'] == 2: # translatedText = gs.translate(req['message'], language2) print "Stuff" print translatedText # direct_To = firebase.get('https://vivid-inferno-6896.firebaseio.com/123456789/123456789/messages/0/for') # print direct_To # messageList = Firebase('https://vivid-inferno-6896.firebaseio.com/123456789/123456789/messages') # print "Before" + messageList # language1 = Firebase('https://vivid-inferno-6896.firebaseio.com/123456789/123456789/language1').get() # print language1 # language2 = Firebase('https://vivid-inferno-6896.firebaseio.com/123456789/123456789/language2').get() # print language2 # if gs.detect(inputMessage) == language1: #Confirms language of input text # outputMessage = gs.translate(inputMessage,language2); # #Add condition which changes value of "for" field based on last "for" value in previous message dictionary # messageList.post({"text":"outputMessage","for":"1","read":"false"}) # print "After" + messageList except Exception, err: print traceback.format_exc()
def main(): """ """ root_reference = Firebase('https://burning-fire-8681.firebaseio.com') this_event_ref = root_reference.child('zE0001') R1_ref = this_event_ref.child('R1') R2_ref = this_event_ref.child('R2') R3_ref = this_event_ref.child('R3') for eun in range(1,11,1): for R_ref in [R1_ref, R2_ref, R3_ref]: eu_ref = R_ref.child("eu_{}".format(get_euns(eun))) eu_ref.put( { "n": random.randint(0,15), "mn": random.randint(0,15), "my": random.randint(0,15), "y": random.randint(0,15) } )
talk['avatar'], 'twitter': set_twitter(talk['twitter']), 'votes': [""], 'active': True }) final_output.update(output) for room in rooms: map_rooms(room) with open('config.json', 'r') as outfile: data_config = json.loads(outfile.read()) db_name = data_config["config"]["pycon_db"] f = Firebase('https://pycon-630b8.firebaseio.com/' + db_name + '/') f.child('rooms').set(final_output) f.child('main').set(data_config) csv_file.close() with open('data.json', 'w') as outfile: output_json = json.dump(final_output, outfile, sort_keys=False, indent=4, ensure_ascii=False) print("Conversion is done")
fb = Firebase('http://gamma.firebase.com/mikexstudios/zephyr') #Subscribe to the most popular zephyr classes zephyr.Subscriptions().add(('help', '*', '*')) zephyr.Subscriptions().add(('sipb', '*', '*')) zephyr.Subscriptions().add(('mxh', '*', '*')) #for testing #To send a message, ex. #zephyr.ZNotice(cls='sipb', message="zsig\x00Message body\n", ...).send() #Wait for messages. It's probably better to poll for messages than to use #blocking loop. print 'Listening to zephyr messages...' while True: m = zephyr.receive(True) #True -> blocks up to a minute [zsig, body] = m.message.split("\x00") body = body.strip() #Send message to Firebase ref = fb.child(m.cls) #separate by class ref.push({'class': m.cls, 'instance': m.instance, 'sender': m.sender, 'time': m.time, #seconds since epoch 'zsig': zsig, 'body': body,}) print "%s / %s / %s %s (%s)\n %s" % (m.cls, m.instance, m.sender, time.ctime(m.time), zsig, body)
from bs4 import BeautifulSoup as bs from firebase import Firebase import requests, html5lib import time import unicodedata while True: print "@@@@@@@@@@@@@@@@@@ new check @@@@@@@@@@@@@@@@@@@@" start_time = time.time() fire = Firebase('https://monitor-6d32c.firebaseio.com') item = fire.child('item').get() for link in item: folder = link.encode('ascii', 'ignore') link = fire.child('item').child(folder).child('url').get() text = '' #Input Link #link = raw_input("Type Link :") html = requests.get(link).text soup = bs(html, 'lxml') #nosize item sold = soup.find('a', class_='selected') if (sold != None): isSold = sold.get('data-sold-out') else: print("not eligible site") continue if (isSold == "false"):