bestandless
best&less account stuff
Python command line script to register, lookup, edit, delete accounts. The accounts are sorted by email address.
Changes from current:
ask twice for email and password
force captive
For every account:
Creates a config file. Creates a json object. Creates a markdown blog post with python-nikola. Creates socially awkward seal GOODBYE FIRSTNAME, HELLO FIRSTNAME meme.
3 database record of previous entries.
gender - display male.jpg for male and female.jpg for female
Gets art quote of the day and replaces art with fashion. add fashion to middle of authors name. add quote to top of blog post. TODO: display quote as image
random choice of clothes. Pregenerated random, recommended. currently random choice of -
In [ ]:
In [1]:
import requests
import bs4
import getpass
import json
import shutil
import PIL
import json
from PIL import ImageDraw, ImageFont
import os
#import arrow
import configparser
In [2]:
myusr = getpass.getuser()
In [3]:
import arrow
In [4]:
loginda = input('Enter first name: ')
loglast = input('Enter last name: ')
print('Suggestions {}{}'.format(loginda, loglast))
userset = input('Enter username: ')
logemail = input('Enter email: ')
emailtwic = input('Enter email again: ')
if logemail == emailtwic:
print('Email are the same')
else:
print('Email is not the same')
bodenter = input('date of birth: YEAR/MNTH/DAY: ')
datebith = arrow.get(bodenter)
datebithz = datebith.strftime('%Y')
passent = getpass.getpass('Enter password: ')
passagain = getpass.getpass('Enter password again: ')
if passent == passagain:
print('They are correct')
else:
print('They are not correct')
imgend = input('gender: ')
#import ConfigParser
config = configparser.RawConfigParser()
# When adding sections or items, add them in the reverse order of
# how you want them to be displayed in the actual file.
# In addition, please note that using RawConfigParser's and the raw
# mode of ConfigParser's respective set functions, you can assign
# non-string values to keys internally, but will receive an error
# when attempting to write to a file or when you get it in non-raw
# mode. SafeConfigParser does not allow such assignments to take place.
config.add_section(logemail)
config.set(logemail, 'firstname', loginda)
config.set(logemail, 'lastname', loglast)
config.set(logemail, 'email', logemail)
# Writing our configuration file to 'example.cfg'
with open('/home/pi/.config/bestless.ini', 'w') as configfile:
config.write(configfile)
In [5]:
import os
import random
In [92]:
if imgend == 'male':
genpat = ('/galleries/male.jpg')
rancho = random.choice(os.listdir('/home/pi/memetest/galleries/male/'))
genshit = ('/galleries/male/{}'.format(rancho))
#gmal = requests.get('https://api.gilt.com/v1/sales/men/upcoming.json?apikey=bb7cf716ec52e7a7737705f0129ed4282a35239a0a6b8a821e68f30a00ecc1a7')
elif imgend == 'female':
genpat = ('/galleries/female.jpg')
rancho = random.choice(os.listdir('/home/pi/memetest/galleries/female/'))
#gmal = requests.get('https://api.gilt.com/v1/sales/women/upcoming.json?apikey=bb7cf716ec52e7a7737705f0129ed4282a35239a0a6b8a821e68f30a00ecc1a7')
genshit = ('/galleries/female/{}'.format(rancho))
In [71]:
#salejs = gmal.json()
In [78]:
#salelen = len(salejs['sales'])
In [87]:
#for salele in range(salelen):
# print(salejs['sales'][salele]['description'])
# print(salejs['sales'][salele]['image_urls']['686x374'][0]['url'])
In [65]:
#requests.get('https://api.gilt.com/v1/sales/men/upcoming.json?apikey=bb7cf716ec52e7a7737705f0129ed4282a35239a0a6b8a821e68f30a00ecc1a7')
Out[65]:
In [ ]:
#https://api.gilt.com/v1/sales/women/active.json?apikey=bb7cf716ec52e7a7737705f0129ed4282a35239a0a6b8a821e68f30a00ecc1a7
In [7]:
genshit
Out[7]:
In [8]:
#import random
In [9]:
#ranum = random.randint(100,1000)
In [10]:
#for it in range(100,1000):
# print('suggestion: {}{}{}'.format(loginda, loglast, it))
In [11]:
#ranum
In [12]:
#reqgif = requests.get('http://api.giphy.com/v1/gifs/search?q={}+fashion&api_key=ee58ff1d10c54fd29ddb0388126c2bcd'.format(datebith))
In [13]:
#gifjs = reqgif.json()
In [14]:
#for himg in range(25):
# img_data = requests.get(gifjs['data'][himg]['images']['fixed_height']['url']).content
# with open('{}.gif'.format(str(himg)), 'wb') as handler:
# handler.write(img_data)
# print(gifjs['data'][himg]['images']['fixed_height']['url'])
In [15]:
with open('/home/{}/account.json'.format(myusr), 'r') as accdict:
readd = accdict.read()
readdict = json.loads(readd)
In [16]:
#readdict = json.loads(readd)
In [17]:
#print(readdict)
In [18]:
emailup = input('Email to lookup: ')
In [19]:
print(readdict[emailup])
In [20]:
emailcont = ('Hello {},\n\nToday we have sale on {}. It is suitable for someone born {}.\n\nHave a great day,\n\nbest&less.'.format(loginda, imgend, datebith.humanize(), str(datebithz)))
In [21]:
emailcont
Out[21]:
In [ ]:
In [22]:
lenid = len(readdict)
In [23]:
nexid = lenid + 1
In [24]:
textzero = 'BYE ' + loginda
textone = 'HELLO ' + loginda
upzero = textzero.upper()
botzero = textone.upper()
# In[ ]:
In [25]:
botzero
Out[25]:
In [26]:
#gheigh = (gtm['height'])
#gwth = (gtm['width'])
#response = requests.get(gtm['url'], stream=True)
#with open('{}{}-reference.jpg'.format(repathz, str(rdz.author)), 'wb') as out_file:
# shutil.copyfileobj(response.raw, out_file)
# del response
#with open('/home/{}/memetest/galleries/{}.png'.format(myusr, gtm['id']), 'wb') as out_file:
# shutil.copyfileobj(response.raw, out_file)
# del response
img = PIL.Image.open('/home/{}/Downloads/seal.jpg'.format(myusr))
imageSize = img.size
print(imageSize)
# find biggest font size that works
fontSize = int(imageSize[1]/5)
print(fontSize)
font = ImageFont.truetype("/home/{}/impact.ttf".format(myusr), fontSize)
topTextSize = font.getsize(upzero)
bottomTextSize = font.getsize(botzero)
print(topTextSize)
while topTextSize[0] > imageSize[0]-20 or bottomTextSize[0] > imageSize[0]-20:
fontSize = fontSize - 1
font = ImageFont.truetype("/home/{}/impact.ttf".format(myusr), fontSize)
topTextSize = font.getsize(upzero)
bottomTextSize = font.getsize(botzero)
print(bottomTextSize)
# find top centered position for top text
topTextPositionX = (imageSize[0]/2) - (topTextSize[0]/2)
topTextPositionY = 0
topTextPosition = (topTextPositionX, topTextPositionY)
# find bottom centered position for bottom text
bottomTextPositionX = (imageSize[0]/2) - (bottomTextSize[0]/2)
bottomTextPositionY = imageSize[1] - bottomTextSize[1] -10
bottomTextPosition = (bottomTextPositionX, bottomTextPositionY)
draw = ImageDraw.Draw(img)
outlineRange = int(fontSize/15)
for x in range(-outlineRange, outlineRange+1):
for y in range(-outlineRange, outlineRange+1):
draw.text((topTextPosition[0]+x, topTextPosition[1]+y), upzero, (0,0,0), font=font)
draw.text((bottomTextPosition[0]+x, bottomTextPosition[1]+y), botzero, (0,0,0), font=font)
draw.text(topTextPosition, upzero, (255,255,255), font=font)
draw.text(bottomTextPosition, botzero, (255,255,255), font=font)
img.save("/home/{}/memetest/galleries/{}.jpg".format(myusr, str(nexid)))
#print(gtm['id'])
#filemh = gtm['id']
#print('hello')
In [27]:
#reqote = requests.get('https://www.goodreads.com/quotes/tag/clothes')
In [28]:
somequote = requests.get('http://quotes.rest/qod.json?category=art')
In [29]:
quotejs = (somequote.json())
In [30]:
myqute = (quotejs['contents']['quotes'][0]['quote'])
In [31]:
lenqute = (quotejs['contents']['quotes'][0]['length'])
In [32]:
qutefas = myqute.replace('art', 'fashion')
In [33]:
qutefas
Out[33]:
In [34]:
quoteauth = quotejs['contents']['quotes'][0]['author']
In [35]:
auspit = quoteauth.split(' ')
In [36]:
fashauthz = (auspit[0] + " 'fashion' " + auspit[1])
In [37]:
bothquote = '"' + qutefas + '" - ' + fashauthz
In [38]:
print(bothquote)
In [ ]:
In [39]:
print(lenqute)
In [40]:
lenqute
Out[40]:
In [41]:
#if lenqute < 20:
In [42]:
#print(quotejs['contents']['quotes'][0]['id'])
In [43]:
#float(lenqute) /2
In [44]:
#gheigh = (gtm['height'])
#gwth = (gtm['width'])
#response = requests.get(gtm['url'], stream=True)
#with open('{}{}-reference.jpg'.format(repathz, str(rdz.author)), 'wb') as out_file:
# shutil.copyfileobj(response.raw, out_file)
# del response
#with open('/home/{}/memetest/galleries/{}.png'.format(myusr, gtm['id']), 'wb') as out_file:
# shutil.copyfileobj(response.raw, out_file)
# del response
img = PIL.Image.open('/home/pi/Downloads/seal.jpg')
imageSize = img.size
print(imageSize)
# find biggest font size that works
fontSize = int(imageSize[1]/5)
print(fontSize)
font = ImageFont.truetype("/home/{}/impact.ttf".format(myusr), fontSize)
topTextSize = font.getsize(quotejs['contents']['quotes'][0]['quote'])
#bottomTextSize = font.getsize(quotejs['contents']['quotes'][0]['quote'])
print(topTextSize)
while topTextSize[0] > imageSize[0]-20:
fontSize = fontSize - 1
font = ImageFont.truetype("/home/{}/impact.ttf".format(myusr), fontSize)
topTextSize = font.getsize(quotejs['contents']['quotes'][0]['quote'])
#bottomTextSize = font.getsize(quotejs['contents']['quotes'][0]['quote'])
#print(bottomTextSize)
# find top centered position for top text
topTextPositionX = (imageSize[0]/2) - (topTextSize[0]/2)
topTextPositionY = 100
topTextPosition = (topTextPositionX, topTextPositionY)
# find bottom centered position for bottom text
#bottomTextPositionX = (imageSize[0]/2) - (bottomTextSize[0]/2)
#bottomTextPositionY = imageSize[1] - bottomTextSize[1] -10
#bottomTextPosition = (bottomTextPositionX, bottomTextPositionY)
draw = ImageDraw.Draw(img)
outlineRange = int(fontSize/15)
for x in range(-outlineRange, outlineRange+1):
for y in range(-outlineRange, outlineRange+1):
draw.text((topTextPosition[0]+x, topTextPosition[1]+y), quotejs['contents']['quotes'][0]['quote'], (0,0,0), font=font)
#draw.text((bottomTextPosition[0]+x, bottomTextPosition[1]+y), quotejs['contents']['quotes'][0]['quote'], (0,0,0), font=font)
draw.text(topTextPosition, quotejs['contents']['quotes'][0]['quote'], (255,255,255), font=font)
#draw.text(bottomTextPosition, quotejs['contents']['quotes'][0]['quote'], (255,255,255), font=font)
img2 = img.crop((0, 80, 610,200))
#img2.save("img2.jpg")
img2.save("/home/{}/memetest/galleries/{}.jpg".format(myusr, str(quotejs['contents']['quotes'][0]['id'])))
#print(gtm['id'])
#filemh = gtm['id']
#print('hello')
In [ ]:
In [ ]:
In [45]:
#print(reqote)
In [46]:
#quotbs = bs4.BeautifulSoup(reqote.text)
In [47]:
#print(quotbs)
In [48]:
#allquote = quotbs.find('div', {'class' : "quoteText"})
In [49]:
#print(quotbs.find_all('a'))
In [50]:
#for allq in allquote:
# print(allq)
In [ ]:
In [51]:
accdict = ({logemail : dict({'firstname' : loginda, 'lastname' : loglast, 'email' : logemail, 'password' : 'hashthis', 'gender': imgend, 'agehuman' : datebith.humanize(),'dob' : bodenter, 'id' : nexid, 'image' : '/galleries/{}.jpg', 'username' : userset, 'post' : '/posts/{}.md'.format(str(nexid), str(nexid))})})
In [52]:
#print(accdict)
In [53]:
import json
In [54]:
z = {**readdict, **accdict}
In [55]:
z
Out[55]:
In [56]:
#json.dumps(accdict)
In [57]:
with open('/home/pi/account.json', 'w') as blacc:
blacc.write(json.dumps(z))
In [58]:
#cat /home/pi/account.json
In [59]:
timnow = arrow.now()
In [60]:
timnowz = timnow.datetime
In [61]:
#print(timnowz)
In [62]:
with open('/home/{}/memetest/posts/{}.md'.format(myusr, str(nexid)), 'w') as resulmd:
resulmd.write('{}\n\n\n\n First name: {}\n\nLast name: {}\n\nEmail: {}\n\nGender: {}\n\n{}\n\n\n\n'.format(bothquote, str(nexid), str(nexid), loginda, loglast, logemail, imgend, emailcont, genpat, genshit))
with open ('/home/{}/memetest/posts/{}.meta'.format(myusr, str(nexid)), 'w') as opmetat:
#opmetat.write("{}".format(str(curtim))
#for arage in alltags:
# print(arage)
opmetat.write('.. title: {}\n.. slug: {}\n.. date: {}\n.. tags: \n.. link:\n.. description:\n.. type: text'.format(str(nexid), str(nexid), timnowz))
In [63]:
#with open('/home/pi/hugosite/content/post/{}.md'.format(str(nexid)), 'w') as hupost:
# hupost.write('+++\ndate = "{}"\ntitle = {}\n\n+++\n\nFirst name: {}\n\nLast name: {}\n\nUsername: {}\n\nEmail: {}\n\nGender: {}'.format(timnowz, str(nexid), loginda, loglast, logemail, imgend))
#hupost.write('+++\ndate = "{}"\ntitle = {}\n\n+++\n\nFirst name: '.format(timnowz))
In [91]:
#for salele in range(salelen):
# descript = (salejs['sales'][salele]['description'])
# imurl = (salejs['sales'][salele]['image_urls']['686x374'][0]['url'])
# with open('/home/{}/memetest/posts/{}.md'.format(myusr, str(nexid)), 'a') as resulmd:
# resulmd.write('\n\n\n\n'.format(imurl))
In [ ]:
In [64]:
#cat /home/pi/hugosite/content/post/6.md
In [ ]:
In [ ]:
In [ ]:
In [ ]:
Comments
Comments powered by Disqus