Skip to content

Commit

Permalink
Adding a xml to contain user keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
kosmicFly committed Oct 22, 2017
1 parent c43e0a4 commit e76552a
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 14 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@
*.db-shm
*.db-wal

Pi/errorlog.txt
Pi/locationlog.txt
Pi/mimiclog.txt

Pi/TwitterKeys.xml
43 changes: 33 additions & 10 deletions Pi/GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from threading import Thread
import re
from Naked.toolshed.shell import execute_js, muterun_js
from kivy.garden.gauge import Gauge
import os
import signal
import multiprocessing, signal
Expand Down Expand Up @@ -45,15 +44,39 @@
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition, WipeTransition, SwapTransition
import tweepy

#Twitter API credentials
consumer_key = "qsaZuBudT7HRaXf4JU0x0KtML"
consumer_secret = "C6hpOGEtzTc9xoCeABgEnWxwWXjp3qOIpxrNiYerCoSGXZRqEd"
access_key = "896619221475614720-MBUhORGyemI4ueSPdW8cAHJIaNzgdr9"
access_secret = "Lu47Nu4eQrtQI1vmKUIMWTQ419CmEXSZPVAyHb8vFJbTu"
#authorize twitter, initialize tweepy
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
import xml.etree.ElementTree as etree

# Twitter API credentials
consumerKey = ''
consumerSecret = ''
accessToken = ''
accessTokenSecret = ''

# Retrieving key and tokens used for 0Auth
tree = etree.parse('TwitterKeys.xml')
root = tree.getroot()
for child in root:
if child.tag == 'ConsumerKey' and child.text is not None:
consumerKey = child.text
print("Consumer Key: " + consumerKey)
elif child.tag == 'ConsumerSecret' and child.text is not None:
consumerSecret = child.text
print("Consumer Secret: " + consumerSecret)
elif child.tag == 'AccessToken':
accessToken = child.text
print("Access Token: " + accessToken)
elif child.tag == 'AccessTokenSecret':
accessTokenSecret = child.text
print("Access Token Secret: " + accessTokenSecret)
else:
print("Warning: Unknown or Empty element: " + child.tag)
print(" Twitter fetching may not work.")

#OAuth process, using the keys and tokens
auth = tweepy.OAuthHandler(consumerKey, consumerSecret)
auth.set_access_token(accessToken, accessTokenSecret)

# Creation of the actual interface, using authentication
api = tweepy.API(auth)

errorlog = open('./Logs/errorlog.txt','w')
Expand Down
7 changes: 7 additions & 0 deletions Pi/TwitterKeys.xml.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" ?>
<TwitterKeys>
<ConsumerKey></ConsumerKey>
<ConsumerSecret></ConsumerSecret>
<AccessToken></AccessToken>
<AccessTokenSecret></AccessTokenSecret>
</TwitterKeys>
44 changes: 44 additions & 0 deletions Pi/teststuff/TwitterAPI_SetupTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import tweepy
import xml.etree.ElementTree as etree

# Twitter API credentials
consumerKey = ''
consumerSecret = ''
accessToken = ''
accessTokenSecret = ''

# Retrieving key and tokens used for 0Auth
tree = etree.parse('../TwitterKeys.xml')
root = tree.getroot()
for child in root:
if child.tag == 'ConsumerKey' and child.text is not None:
consumerKey = child.text
print("Consumer Key: " + consumerKey)
elif child.tag == 'ConsumerSecret' and child.text is not None:
consumerSecret = child.text
print("Consumer Secret: " + consumerSecret)
elif child.tag == 'AccessToken':
accessToken = child.text
print("Access Token: " + accessToken)
elif child.tag == 'AccessTokenSecret':
accessTokenSecret = child.text
print("Access Token Secret: " + accessTokenSecret)
else:
print("Warning: Unknown or Empty element: " + child.tag)
print(" Twitter fetching may not work.")

#OAuth process, using the keys and tokens
auth = tweepy.OAuthHandler(consumerKey, consumerSecret)
auth.set_access_token(accessToken, accessTokenSecret)

# Creation of the actual interface, using authentication
api = tweepy.API(auth)

# Testing your account
api.update_status('Hello Python Central!')
print("Check your twitter page for the status \"Hello Python Central!\"")

# Testing retrieve from mimic twitter.
# comment out line 38 before uncommenting the following.
#stuff = api.user_timeline(screen_name = 'iss_mimic', count = 1, include_rts = True, tweet_mode = 'extended')
#print(stuff)

0 comments on commit e76552a

Please sign in to comment.