public
Created

Thought Log + Dropbox SDK

  • Download Gist
thoughtlogdropbox.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
# Include the Dropbox SDK libraries
from dropbox import client, rest, session
import easygui
import subprocess
import webbrowser
from time import gmtime, strftime
 
name = easygui.enterbox(msg='Enter your name:', title='Name query')
if str(name).lower() == "Gian":
subprocess.call(['say','Welcome Inventor'])
easygui.msgbox(
msg= 'Welcome back Inventor Gian. You thoughts will be safe with me.',
title='You have completed one thought log',
ok_button='FINISH',
image=None,
root=None)
 
#f, metadata = client.get_file_and_metadata('/magnum-opus.txt',rev='362e2029684fe')
#out = open('magnum-opus.txt', 'w')
#out.write(f)
#print(metadata)
 
#Makes variable for the current time for logging
current_time = strftime("%a, %d %b %Y %H:%M:%S", gmtime())
f1 = open('Gian\'s Log.txt', 'a')
f1.write('\n' + name + '\n')
f1.write(current_time + '\n')
f1.close()
 
#Asks for input on users current situation, thoughts, emotions and behavior.
situation = ['SITUATION:(Example: Waiting for a friend who is late.)']
thoughts = ['THOUGHTS:(Example: My friend Bob\'s is always late!)']
emotions = ['EMOTIONS:(Example: Mad & Stressed)']
behavior = ['BEHAVIOR:(Example: Arguing with family)']
field1 = easygui.multenterbox(name + ', please fill in the blanks', 'Gians Thought Log', situation + thoughts + emotions + behavior)
 
f2 = open(name + '''\'s Log.txt''', 'a')
f2.write('SITUATION: ' + str(field1[0]) + '\n')
f2.write('THOUGHTS: ' + str(field1[1]) + '\n')
f2.write('EMOTIONS: ' + str(field1[2]) + '\n')
f2.write('BEHAVIOR: ' + str(field1[3]) + '\n')
f2.close()
 
 
if str(field1[1]).lower() == "always":
easygui.msgbox(
msg= ''' !!!!!
A possible overgeneralization was detected.
The Thinking Trap auto detector identifyed a possible thinking trap. \n
You said "Always" in the thoughts enterbox.''',
title='Thinking Trap Detected',
ok_button='FINISH',
image=None,
root=None)
 
elif str(field1[1]).lower() != "always":
easygui.msgbox(
msg= 'The Thinking Trap auto detector did not detect any Thinking Traps.',
title='Thinking Trap Detected',
ok_button='FINISH',
image=None,
root=None)
#Lists field1 and thinking traps so that the user can identify thinking traps
thinking_trapsgui = easygui.enterbox(msg= name +', please identify your thinking traps: \n \n'
'FORTUNE-TELLING: This occurs when we predict that things will turn out badly. However, we cannot predict the future because we don\'t have a magic ball! \n \n'
'MIND-READING: This happens when we believe that we know what others are thinking and we assume that they\'re thinking the worst of us. However, we cannot mind-read so we do not know what others are thinking! \n \n'
'LABELING: Sometimes we talk to ourselves in a mean way and we use a single negative word to describe ourselves. However, this kind of thinking is unfair and we\'re too complex to be summed up in a single word! \n \n'
'FILTERING: This happens when we take note of all the bad things that happen, but ignore any good things. \n \n'
'OVERESTIMATING: This happens when we believe that something that\'s unlikely to occur is actually about to happen. \n \n'
'CATASTROPHIZING: This is when we imagine the worst possible thing is about to happen and we will be unable to cope with it. \n \n'
'OVERGENERALIZING: This is when we use words like always or never to describe situations or events. This is a problematic way of thinking because it doesn\'t take all situations or events into account \n \n'
+ str(field1),
title='Gians Thought Log')
 
f3 = open(name + '''\'s Log.txt''', 'a')
f3.write('THINKING TRAPS: ' + thinking_trapsgui + '\n')
f3.close()
 
#Alternate thoughts and behavior Multi Variable Mult Enter Box
alternate_behavior = ['ALTERNATE BEHAVIOR: \n Example: Find a constructive way to calm down. \n']
alternate_thoughts = ['ALTERNATE THOUGHTS: \n Example: He probably has a good reasong to be late.']
field2 = easygui.multenterbox(name + ', please fill in the blanks', 'Gians Thought Log', alternate_behavior + alternate_thoughts)
 
f4 = open(name + '''\'s Log.txt''', 'a')
f4.write('ALT THOUGHTS: ' + str(field2[0]) + '\n')
f4.write('ALT BEHAVIOR: ' + str(field2[1]) + '\n')
f4.close()
 
#Lets the user know that they have completed a thought log.
finish = easygui.msgbox(
msg= '''
Congratulations!
--------------------------------------------------
You\'ve completed a thought log! Your thoughts will be logged,
along with the current date and time to a file called Log.txt.
''',
title='You have completed one thought log',
ok_button='FINISH',
image=None,
root=None
)
 
# Get your app key and secret from the Dropbox developer website
APP_KEY = ''
APP_SECRET = ''
 
# ACCESS_TYPE should be 'dropbox' or 'app_folder' as configured for your app
ACCESS_TYPE = 'app_folder'
 
sess = session.DropboxSession(APP_KEY, APP_SECRET, ACCESS_TYPE)
 
request_token = sess.obtain_request_token()
 
# Make the user sign in and authorize this token
url = sess.build_authorize_url(request_token)
webbrowser.open_new_tab(url)
easygui.enterbox(msg= "Please visit this URL by copying and pasting it into your browser and press the 'Allow' or 'Continue' button, then hit 'OK' here. \n \n",
title= "URL",
default= str(url),
image= "dropbox.gif"
)
 
# This will fail if the user didn't visit the above URL and hit 'Allow'
access_token = sess.obtain_access_token(request_token)
 
# This will display a window with info about the linked account
#client = client.DropboxClient(sess)
#easygui.msgbox(
# msg= "Linked account: \n\n" + str(client.account_info()),
# title= "Linked account",
# ok_button= "OK",
# image= "dropbox.gif"
# )
 
# This will display a window notifying the user that their log has been uploaded to dropbox
client = client.DropboxClient(sess)
file_directory = open('''/Users/gianlazzarini/Documents/Aptana Studio 3 Workspace/Thought Log 3 w dropbox/src/Gian's Log.txt''')
file_name = 'Gian\'s Log ' + current_time + '.txt'
response = client.put_file(file_name, file_directory)
response
easygui.msgbox(
msg="YOUR LOG HAS BEEN UPLOADED \n\n",
title="uploaded",
ok_button="OK",
image= "install_graphic.gif"
)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.