Exemple #1
0
    def testSeekJsonScript(self):
        de = dataencryptor.DataEncryptor()
        if not os.path.isdir(de.dataDir + "/testFolder"):
            os.mkdir(de.dataDir + "/testFolder")

        de.setPath(de.dataDir + "/testFolder")
        for i in range(0, 4):
            handle = open(de.dataDir + "/test" + str(i) + ".json", 'w+')
            handle.write("Welcome to the test file")
            handle.close()

        de.seekJson() # Encrypt all .json files and delete them

        self.assertTrue(os.path.isfile(de.dataDir + "/test0.json.encrypted.zip"))
        self.assertTrue(os.path.isfile(de.dataDir + "/test1.json.encrypted.zip"))
        self.assertTrue(os.path.isfile(de.dataDir + "/test2.json.encrypted.zip"))
        self.assertTrue(os.path.isfile(de.dataDir + "/test3.json.encrypted.zip"))

        self.assertFalse(os.path.isfile(de.dataDir + "/test0.json"))
        self.assertFalse(os.path.isfile(de.dataDir + "/test1.json"))
        self.assertFalse(os.path.isfile(de.dataDir + "/test2.json"))
        self.assertFalse(os.path.isfile(de.dataDir + "/test3.json"))

        de.seekJson()

        self.assertTrue(os.path.isfile(de.dataDir + "/test0.json"))
        self.assertTrue(os.path.isfile(de.dataDir + "/test1.json"))
        self.assertTrue(os.path.isfile(de.dataDir + "/test2.json"))
        self.assertTrue(os.path.isfile(de.dataDir + "/test3.json"))
Exemple #2
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()
Exemple #3
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
Exemple #4
0
    def testGetDict(self):
        handle = open(str(Path.home()) + "/.ssh/encrypted-data/unittest.json", 'w+')
        handle.write("{\
    \"Test1\":\"Value1\",\
    \"Test2\":\"Value2\",\
    \"Test3\":\"AbsolutelyNotValue3\"}")
        handle.close()
        de = dataencryptor.DataEncryptor(filename="unittest")
        dict = de.getDict()

        self.assertIsNotNone(dict, "getDict() has returned None value")
        self.assertTrue(dict["Test3"] == "AbsolutelyNotValue3",
                        "Values contained in Dict weren't do not match expected results")
Exemple #5
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()
Exemple #6
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)
Exemple #7
0
 def testEncryption(self):
     de = dataencryptor.DataEncryptor()
     with open("./testencryption.json", "w+") as handle:
         handle.write("This is a test")
         handle.close()
Exemple #8
0
 def testInitDataEncryptor(self):
     self.assertIsNotNone(dataencryptor.DataEncryptor())
     self.assertIsNotNone(dataencryptor.DataEncryptor("Test.json"))