trackdrop

Track Drop

Logging information. asks for input. saves json and tweets. doesn't save/tweet if ID is not unique. Generate 12 character ID.

In [32]:
import arrow
import getpass
import string
import random
import json
import tweepy
import os
from pathlib import Path
In [33]:
timnow = arrow.now()

myusr = getpass.getuser()
In [34]:
dateti = timnow.datetime
In [35]:
def idgenr(size=12, chars=string.ascii_uppercase):
    return ''.join(random.choice(chars) for _ in range(size))
In [18]:
jslis = os.listdir('/home/{}/medtest/'.format(myusr))

meddir = ('/home/{}/medtest/'.format(myusr))
In [36]:
theid = idgenr()
In [37]:
print(theid)
LDUDBTKRMGGT
In [ ]:
amountake = input('number of drops: ')
In [11]:
cort = input('C or T ')
C or T C
In [12]:
comnow = input('Comments: ')
Comments: fine
In [13]:
medhis = dict()
In [14]:
medhis.update({theid : dict({'drops' : amountake, 'datetime' : str(dateti), 'type' : cort, 'comments' : comnow, 'user' : myusr})})
In [15]:
meddum = json.dumps(medhis)
In [16]:
print(meddum)
{"HKJZABUIRYII": {"datetime": "2017-01-04 10:49:46.499037+13:00", "comments": "fine", "drops": "2", "user": "pi", "type": "C"}}
In [78]:
with open('/home/{}/wck.txt'.format(myusr), 'r') as wckz:
    allkey = wckz.readlines()
    OAUTH_TOKEN = allkey[0]
    #print(OAUTH_TOKEN)
    OAUTH_SECRET = allkey[1]
    CONSUMER_KEY = allkey[2]
    CONSUMER_SECRET = allkey[3]
   
auth = tweepy.OAuthHandler(CONSUMER_KEY.strip('\n'), CONSUMER_SECRET.strip('\n'))
auth.set_access_token(OAUTH_TOKEN.strip('\n'), OAUTH_SECRET.strip('\n'))

api = tweepy.API(auth)
In [31]:
my_file = Path(meddir + theid + '.json')
if my_file.is_file():
    print('file exists')
else:
    print('file not there')
    with open('{}{}.json'.format(meddir, theid), 'w') as mete:
        mete.write(meddum)
    
    api.update_status('Med {} drops {}. {}'.format(cort, amountake, comnow))
file not there

Comments

Comments powered by Disqus