Code for Unit 2 Project

Nigel Li

#Create GUI
from Tkinter import *
import sys
#gather twitter module
from twython import *
import datetime
import os

#Authentication variables
access_key = "767723777958420481-eLxPwGgY9NvJQa3MESxMBbQXYfLtFq8"
access_secret =     "2zfdXkjSIJyeyeo9ANMDtXJIg0uxieMvl5tD6JA7r3dhj"
consumer_key = "Yz2dZAC7KWq1NcMlPvaFIR8xa"
consumer_secret =     "oD2Wkp2toCGAfrXLHcG2Gb904LBwGOGCiZtOxbCHiXrEhzHAOZ"

#designate api as twitter authetication
api = Twython(consumer_key, consumer_secret, access_key, access_secret)

tweet1 = "There is poop in the toilet %s"

tweet2 = "The toilet is flooded %s"

tweet3 = "The toilet is clogged %s"

i = datetime.datetime.now()#Assign variable for date and time

interface = Tk()#Establish interface 

#Tweets assigned
poop = tweet1 %i #the %i calls the string which will print the date and time

flood = tweet2 %i

clogged = tweet3 %i

########## FUNCTIONS ###################

def post1():
    api.update_status(status= tweet1 %i) 
    python = sys.executable #exits the programme and restarts it         
    os.execl(python, python, * sys.argv)
    
def post2():
    api.update_status(status= tweet2 %i)
    python = sys.executable
    os.execl(python, python, * sys.argv)

def post3():
    api.update_status(status= tweet3 %i)
    python = sys.executable
    os.execl(python, python, * sys.argv)
   
########################################

#establish elements of GUI
interface.title("Bathroom Status")
interface.geometry("500x250")

app = Frame(interface)
app.grid()

instructions = Label(app, text = "What is wrong with this bathroom?")
instructions.grid()

#ASSIGNING BUTTONS#
button1 = Button(interface, text = "poop")
button1.grid()
button1["command"] = post1

button2 = Button(interface, text = "flooded")
button2.grid()
button2["command"] = post2

buttonReset = Button(interface, text = "clogged")
buttonReset.grid()
buttonReset["command"] = post3

#loop the gui
interface.mainloop()
datetime.mainloop()