Esempio n. 1
0
    def testGetOneTweet(self):
        de = dataencryptor.DataEncryptor(filename="twitter")
        listener = mystreamlistener.LRITwitterListener()
        auth = de.getDict()
        listener.setLoginData(consumerkey=auth["consumerkey"],
                              consumersecret=auth["consumersecret"],
                              accesstoken=auth["accesstoken"],
                              accesstokensecret=auth["accesstokensecret"])
        try:
            listener.connectAPI()
        except RuntimeError as e:
            print(e.args)
            raise e
        handle = open(
            str(Path.home()) + "/.ssh/encrypted-data/tweets.json", 'w+')
        listener.setOutput(handle)
        listener.setMaxTweets(1)

        try:
            listener.startListening()
        except RuntimeWarning as e:
            print(e.args)
            handle.seek(0)
        #handle.close()
        #with open(str(Path.home()) + "/.ssh/encrypted-data/tweets.json", 'w+') as handle:
        #    parsed = json.load(handle)
        #    print(parsed)
        #handle = open("/.ssh/encrypted-data/tweets.json", 'w+')
        #json.dump(parsed, handle)
        #parsed = json.loads(handle.read())
        #handle.seek(0)
        #json.dump(parsed, handle, indent=4, ensure_ascii=True, sort_keys=True)
        #handle.write(parsed)
        handle.close()
Esempio n. 2
0
 def testConnection(self):
     de = dataencryptor.DataEncryptor(filename="twitter")
     listener = mystreamlistener.LRITwitterListener()
     auth = de.getDict()
     listener.setLoginData(consumerkey=auth["consumerkey"],
                           consumersecret=auth["consumersecret"],
                           accesstoken=auth["accesstoken"],
                           accesstokensecret=auth["accesstokensecret"])
     try:
         listener.connectAPI()
     except RuntimeError as e:
         print(e.args)
         raise e
Esempio n. 3
0
    def testGetOneTweet(self):
        de = dataencryptor.DataEncryptor(filename="twitter")
        listener = mystreamlistener.LRITwitterListener()
        auth = de.getDict()
        listener.setLoginData(consumerkey=auth["consumerkey"],
                              consumersecret=auth["consumersecret"],
                              accesstoken=auth["accesstoken"],
                              accesstokensecret=auth["accesstokensecret"])
        try:
            listener.connectAPI()
        except RuntimeError as e:
            print(e.args)
            raise e
        handle = open(
            str(Path.home()) + "/.ssh/encrypted-data/tweets.json", 'w+')
        listener.setOutput(handle)
        listener.setMaxTweets(1)

        try:
            listener.startListening()
        except RuntimeWarning as e:
            print(e.args)
            handle.seek(0)
        handle.close()
Esempio n. 4
0
from lri import dataencryptor
from lri import mystreamlistener
"""
    Instantiate an DataEncryptor searching for 
    ~/.ssh/encrypted-data/twitter.json or twitter.encrypted.json
    
    Get a dictionary of login data from json file
    
    Set the data in an instance of TwitterListener
    
    Connect to the Twitter API and start listening.
"""

accessGetter = dataencryptor.DataEncryptor("twitter")

logindata = accessGetter.getDict()

twstream = mystreamlistener.LRITwitterListener()

twstream.setLoginData(logindata["consumerid"], logindata["consumersecret"],
                      logindata["accesstoken"], logindata["accesstokensecret"])
twstream.connectAPI()
twstream.startListening()

exit(0)