def _get_all_dweets(self, dweet_thing): dweets = dweepy.get_dweets_for(dweet_thing, '') last_create_date = dateutil.parser.parse('1900-01-01 0:0:0Z') stored_dweets = False for dweet in dweets: print "Monitor dweet = " + str(dweet) createdate = dateutil.parser.parse(dweet['created']) if createdate > self.active_drones[dweet_thing]: thing_uuid = uuid.uuid1() logging.debug('Storing to Cassandra: ' + str(thing_uuid)) try: cassandra_command = self.build_cassandra_command(dweet, thing_uuid, createdate) self._cassandra_session.execute( cassandra_command.command, cassandra_command.values) stored_dweets = True except Exception, e: traceback.print_exc(e) logging.error(str(e)) logging.error("Cassandra: Failed executing INSERT.") if createdate > last_create_date: last_create_date = createdate
def get_all_controller_dweets(self): dweets = dweepy.get_dweets_for(self._dweet_controller, '') last_create_date = dateutil.parser.parse('1900-01-01 0:0:0Z') print dweets for dweet in dweets: create_date = dateutil.parser.parse(dweet['created']) if create_date > self._last_dweet: # Extract the relevant data from the dweet dweet_content = dweet["content"] is_launch = dweet_content["is_launch"] drone_name = dweet_content["drone_name"] # If the dweet says that it is a drone launch and the drone is not currently being followed by the # receiver and the drone has not been already deactivated by the receiver, add it to list of drones if is_launch and drone_name not in self.active_drones: self.active_drones[drone_name] = dateutil.parser.parse('1900-01-01 0:0:0Z') logging.debug("Monitor adding drone") print "monitor adding drone" # If the dweet says that it is not a launch (a disable) and the drone is currently being followed by # the receiver, remove it from the list of drones being followed elif not is_launch and drone_name in self.active_drones: # Remove this drone from the following list self.active_drones.pop(drone_name) logging.debug("Monitor removing drone") print "monitor removing drone" if create_date > last_create_date: last_create_date = create_date # persist the last read dweet by writing the oldest create data from all read dweets bkfile = open(self._bookmark_file, 'w') bkfile.write('{ "last_dweet" : "' + str(last_create_date) + '" }') self._last_dweet = last_create_date
def test_get_dweets_for(self): """`get_all_dweets_for` should return a valid response. """ dweepy.dweet_for(self.my_thing_id, test_data) dweepy.dweet_for(self.my_thing_id, test_data) dweets = dweepy.get_dweets_for(self.my_thing_id) check_valid_get_response(self, dweets)
def getall(args): """get all the messages from the queue""" logger.info('Getting all the messages from %s', args.queue) try: jsonPayLoad = dweepy.get_dweets_for(args.queue) except dweepy.DweepyError as e: logger.exception('Failed to get all the message from queue %s', args.queue) sys.exit(1) payLoad = {} for message in jsonPayLoad: payLoad[message['created']] = message['content']['message'] print json.dumps(payLoad)
def getall(args): """get all the messages from the queue""" logger.info('Getting all the messages from %s', args.queue) try: jsonPayLoad = dweepy.get_dweets_for(args.queue) # except dweepy.DweepyError as e: except dweepy.DweepyError: logger.exception('Failed to get all the message from queue %s', args.queue) # FIXME Where does this exit come from? # Perhaps should be imported from sys? exit(1) payLoad = {} for message in jsonPayLoad: payLoad[message['created']] = message['content']['message'] print json.dumps(payLoad)
def check_updates(): global CHAT, CHAT_ID, UPDATES_CHECK while CHAT_ID == "" and UPDATES_CHECK: pass while UPDATES_CHECK: try: if CHAT == []: CHAT = dweepy.get_dweets_for(CHAT_ID) for dweet in CHAT: date = dweet["created"][12:17] type = dweet["content"]["type"] username = dweet["content"]["username"] if type == "text": data = dweet["content"]["data"] data = str(data)[1:] data = bytes.fromhex(data).decode("utf-8") text_cons = date + " " + username + ": " + data print(text_cons) textCons.config(state=tk.NORMAL) textCons.insert(tk.END, text_cons + "\n") textCons.config(state=tk.DISABLED) textCons.see(tk.END) elif type == "file": text_cons = newdate[12:17] + " " + username + ": sent file " for index in int(newdweet["content"]["data"]["count"]): filename = newdweet["content"]["data"][str(index)]["name"] filename = bytes.fromhex(filename[1:]).decode("utf-8") text_cons += " " + filename textCons.config(state=tk.NORMAL) textCons.insert(tk.END, text_cons + "\n") textCons.config(state=tk.DISABLED) textCons.see(tk.END) else: newchat = dweepy.get_dweets_for(CHAT_ID) # print(newchat) # print('') for newdweet in newchat: newdate = newdweet["created"] checkIS = False for olddweet in CHAT: if olddweet["created"] == newdate: checkIS = True if checkIS == False: type = newdweet["content"]["type"] username = newdweet["content"]["username"] if type == "text": data = newdweet["content"]["data"] data = str(data)[1:] data = bytes.fromhex(data).decode("utf-8") text_cons = newdate[12:17] + " " + username + ": " + data textCons.config(state=tk.NORMAL) textCons.insert(tk.END, text_cons + "\n") textCons.config(state=tk.DISABLED) textCons.see(tk.END) elif type == "file": text_cons = newdate[12:17] + " " + username + ": sent file " for index in range(1, int(newdweet["content"]["data"]["value"]) + 1, 1): filename = newdweet["content"]["data"][str(index)]["name"] filename = bytes.fromhex(filename[1:]).decode("utf-8") if username != USERNAME: data = newdweet["content"]["data"][str(index)]["data"] if os.path.exists("files") == False: os.mkdir("files") with open("files/" + filename, 'wb') as file_: file_.write(bytes.fromhex(data[1:])) file_.close() text_cons += " " + filename textCons.config(state=tk.NORMAL) textCons.insert(tk.END, text_cons + "\n") textCons.config(state=tk.DISABLED) textCons.see(tk.END) CHAT = newchat except Exception as e: if str(e) == "Rate limit exceeded, try again in 1 second(s).": print("delay 1 sec") time.sleep(1.0) time.sleep(5)
"""This file is part of Asphalt Asphalt is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Asphalt is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Asphalt. If not, see <http://www.gnu.org/licenses/>. Copyright © 2016 4Loop """ import dweepy import time dweepy.dweet_for('Edison_1',{'ZonaA':20}) time.sleep(1) dweepy.dweet_for('Edison_1',{'ZonaB':20}) res=dweepy.get_dweets_for('Edison_1') for x in res: print x
import dweepy import time dweepy.dweet_for('Edison_1',{'ZonaA':20}) time.sleep(1) dweepy.dweet_for('Edison_1',{'ZonaB':20}) res=dweepy.get_dweets_for('Edison_1') for x in res: print x
import dweepy # From one Thing # print dweepy.get_latest_dweet_for('this_is_sparta') # Getting the lastest print dweepy.get_dweets_for('this_is_sparta')
def dweet_list(): """ Latest dweets """ object_list = dweepy.get_dweets_for(DWEEPY_NAME) return render_template("dweet_list.html", object_list=object_list)