def getListKeyFromDB(self): """ get all keys from data base no matter which API """ try: db = DB_Manager(engineUrl=self.engineURL) db.db_connection() self.keyList = db.getKey() print(self.keyList) print('Get key list successful') return self.keyList except Exception as exception: print(exception) print('Unable to get list')
def getandwritedb_wetter(locationarea_locationid, apikey): """ Method to get data from owm API and put the data in the correct table of the data base in a while loop every 10 min """ while True: try: weather = OwmHandler(standort=locationarea_locationid, cityid=locationarea_locationid, apikey=apikey) data_weather = weather.getWeather() if data_weather == 0: print("OWM API offline") db = DB_Manager(engineUrl=engineURl) db.db_connection() data = WetterTable(wetterzeit=data_weather[1], locationarea_locationid=data_weather[2], wettertyp=data_weather[3], temperatur=data_weather[4], luftfeuchte=data_weather[5], wolken=data_weather[6], windrichtung=data_weather[7], windgeschwindigkeit=data_weather[8], luftdruck=data_weather[9], regenmenge=data_weather[10], wettertypdetail=data_weather[11], wetterzeitref=data_weather[12]) db.insert(data) db.db_close() time.sleep(600) print('method wetter sucessful') except Exception as exception: print(exception) print('method wetter unable')
def getandwritedb_tweets(locationarea_locationid, geobox, consumer_key, consumer_secret, access_token, access_token_secret): """ Method to add tweet of a specific loacationarea in the correct table of the data base :param locationarea_locationid: :param geobox: can be a list or a tupel specified in the order [long1, lat1, long2 lat2] """ """ In comparison to the other getandwritedb_xxx-methods the received tweets are directly written to the database via the on_status-mehtod of the StreamWatcherListener. """ try: dbconnection = DB_Manager(engineUrl=engineURl) dbconnection.db_connection() tweet = Tweets(dbconnection=dbconnection, locationid=locationarea_locationid, geobox=geobox, consumer_key=consumer_key, consumer_secret=consumer_secret, access_token=access_token, access_token_secret=access_token_secret) tweet.get() dbconnection.db_close() print('method tweets sucessful') except Exception as exception: print(exception) print('method tweets unable')
def getandwritedb_locationarea(locationid, name, long1, lat1, long2, lat2): """ Method to add the locationarea in the correct table of the data base :param locationid: provide by Openweathermap """ try: db = DB_Manager(engineUrl=engineURl) db.db_connection() data = LocationareaTable(locationid=locationid, name=name, long1=long1, lat1=lat1, long2=long2, lat2=lat2) db.insert(data) db.db_close() print('method locationarea sucessful') except Exception as exception: print(exception) print('method locationarea unable')
def getandwritedb_keymanager(keyname, keytype, weatherkey, consumerkey, consumerkeysecret, accesstoken, accesstokensecret): """ Method to add key information of an user in the correct table of the data base :param keyname: perhabs a mixture of the username und the apiname :param keytype: owm or twitter """ try: db = DB_Manager(engineUrl=engineURl) db.db_connection() data = KeymanagerTable(keyname=keyname, keytype=keytype, weatherkey=weatherkey, consumerkey=consumerkey, consumerkeysecret=consumerkeysecret, acesstoken=accesstoken, acesstokensecret=accesstokensecret) db.insert(data) db.db_close() print('method keymanager sucessful') except Exception as exception: print(exception) print('method keymanager unable')
else: location = None stream.filter(locations=location ) #locations=location #track=['nasaberlin'] return #Testing new Twitter if __name__ == '__main__': consumer_key = 'jPk1O1aFiVe70AbWObrWhS5nH' consumer_secret = 'MURs2naGcS6PN6JOh310fuiruL09pjmB5HpzivnSrBHNAGvQq6' access_token = '741956576404242432-9CH2S0U5Fe2oEEM6TWJQqm7HcQkMsJZ' access_token_secret = '6TntDaoD4QWYkvTqcDT0NiGuNWFvxMZsMlPxG7MsNGrrH' dbconnection = DB_Manager( 'mssql://*****:*****@81.169.244.134:1433/TestDatabase2?driver=SQL+Server' ) dbconnection.db_connection() tweet = Tweets(dbconnection=dbconnection, locationid=5128581, geobox=[-74.256566, 40.500388, -73.721076, 40.870018], consumer_key=consumer_key, consumer_secret=consumer_secret, access_token=access_token, access_token_secret=access_token_secret) #geobox = [long1, lat1, long2 lat2] #tweet = Tweets(dbconnection=dbconnection, locationid=1, geobox = [8.333017, 47.894235, 12.001730, 50.308968], consumer_key=consumer_key, #tweet = Tweets(dbconnection=dbconnection, locationid=2951825, geobox = [8.333017, 47.894235, 12.001730, 50.308968], consumer_key=consumer_key, # consumer_secret=consumer_secret, access_token=access_token, access_token_secret=access_token_secret)
stream.filter( locations=location ) #locations=location #track=['nasaberlin'] return except Exception as exception: print(exception) #Testing new Twitter if __name__ == '__main__': consumer_key = 'XXX' consumer_secret = 'XXX' access_token = 'XXX' access_token_secret = 'XXX' dbconnection = DB_Manager('XXX') dbconnection.db_connection() tweet = Tweets(dbconnection=dbconnection, locationid=5128581, geobox=[-74.256566, 40.500388, -73.721076, 40.870018], consumer_key=consumer_key, consumer_secret=consumer_secret, access_token=access_token, access_token_secret=access_token_secret) #geobox = [long1, lat1, long2 lat2] #tweet = Tweets(dbconnection=dbconnection, locationid=1, geobox = [8.333017, 47.894235, 12.001730, 50.308968], consumer_key=consumer_key, #tweet = Tweets(dbconnection=dbconnection, locationid=2951825, geobox = [8.333017, 47.894235, 12.001730, 50.308968], consumer_key=consumer_key, # consumer_secret=consumer_secret, access_token=access_token, access_token_secret=access_token_secret) tweet.get()