In [1]:
import json
In [ ]:
In [2]:
import arrow
In [3]:
def getwholefil(width, height):
return(width * height)
In [4]:
def givearray(inputarray):
return(list(inputarray))
In [5]:
def retwatera(wid, hei, mylis):
return(getwholefil(wid,hei) - sum(givearray(mylis)))
In [6]:
#want to test that the two numbers are int and not str
In [7]:
givearray([2,5,6,2,3])
Out[7]:
In [8]:
retwatera(5,20, [2,3,6,2,3])
Out[8]:
In [9]:
type(givearray('2, 5, 6, 6, 2'))
Out[9]:
In [10]:
givearray('2,5,6,6,2')
Out[10]:
In [11]:
getwholefil(5,10)
Out[11]:
In [12]:
thearray = [1,3,5,2,3]
In [13]:
totfil = 50
In [14]:
getwholefil(5,10) - sum(thearray)
Out[14]:
In [15]:
with open('/home/wcmckee/local.json', 'r') as locj:
print(locj.read())
jsrd = json.loads(locj.read())
In [19]:
from tinydb import TinyDB, Query
db = TinyDB('/home/wcmckee/db.json')
In [3]:
import tinydb
In [26]:
import sqlite3
In [27]:
conn = sqlite3.connect('example.db')
In [28]:
c = conn.cursor()
# Create table
c.execute('''CREATE TABLE identify
(customer_id, first_name, last_name, email, birthdate, gender, marketing_consent)''')
# Insert a row of data
c.execute("INSERT INTO identify VALUES ('00:14:22:01:23:45','William','Mckee','hammer@gmail.com', '1974-08-01', 'male', 'True')")
# Save (commit) the changes
conn.commit()
# We can also close the connection if we are done with it.
# Just be sure any changes have been committed or they will be lost.
conn.close()
In [ ]:
c = conn.cursor()
c.execute("INSERT INTO identify VALUES ('00:14:22:01:23:45','William','Mckee','hammer@gmail.com', '1974-08-01', 'male', 'True')")
conn.commit()
conn.close()
In [29]:
conn = sqlite3.connect('example.db')
c = conn.cursor()
c.execute("INSERT INTO identify VALUES ('00:14:22:01:23:45','William','Mckee','hammer@gmail.com', '1974-08-01', 'male', 'True')")
conn.commit()
conn.close()
In [ ]:
In [30]:
conn = sqlite3.connect('example.db')
In [31]:
cur = conn.cursor()
In [35]:
import sqlite3
persons = [
("Hugo", "Boss"),
("Calvin", "Klein")
]
con = sqlite3.connect(":memory:")
# Create the table
con.execute("create table person(firstname, lastname)")
# Fill the table
con.executemany("insert into person(firstname, lastname) values (?, ?)", persons)
# Print the table contents
for row in con.execute("select firstname, lastname from person"):
print (row)
#print "I just deleted", con.execute("delete from person").rowcount, "rows"
In [ ]:
from tinydb import TinyDB, Query
db = TinyDB('path/to/db.json')
#>>> User = Query()
#>>> db.insert({'name': 'John', 'age': 22})
#>>> db.search(User.name == 'John')
In [ ]:
import tinydb
In [34]:
for row in cur.execute("select first_name"):
print(row)
In [25]:
cur.fetchall()
Out[25]:
In [248]:
def createprofile(customer_id, profilesource):
return('The customer id is {} and the profile source is {}'.format(customer_id, profilesource))
In [249]:
createprofile('hammer@gmail.com', 'facebook')
Out[249]:
In [24]:
def createfullprofile(first_name, last_name, email, marketing_consent, birthdate, gender):
db.insert({'first_name' : first_name, 'last_name' : last_name, 'email' : email, 'marketing_consent' : marketing_consent, 'birthdate' : birthdate, 'gender' : gender})
#return('Hello {} {}. Your email is {}. Marketing opt is {}. Your birthdate is {} and you are a {}'.format(first_name, last_name, email, marketing_consent, birthdate, gender))
return({'first_name' : first_name, 'last_name' : last_name, 'email' : email, 'marketing_consent' : marketing_consent, 'birthdate' : birthdate, 'gender' : gender})
In [27]:
createfullprofile('something', 'else', 'law123@gmail.com', True, '04/12/1001', 'male')
Out[27]:
In [39]:
currentime = arrow.now()
In [252]:
birthday = arrow.get('1865-12-08')
In [253]:
print(birthday)
In [254]:
currentime - birthday
Out[254]:
In [255]:
birthday.date()
Out[255]:
In [256]:
birthday.strftime('%d')
Out[256]:
In [257]:
birthday.strftime('%m')
Out[257]:
In [258]:
birthday.strftime('%Y')
Out[258]:
In [ ]:
first_name string true First name of the customer
last_name string true Last name of the customer
email string false The email of the customer
marketing_consent boolean false Whether the customer gives consent to receive marketing material
birthdate string false The birthdate of the customer in the format YYYY-MM-DD
gender string false The gender of the customer
avatar_image string false An image representing the customer
bio string false A brief description of the customer
hometown string false The home town of the customer
link string false A link to the original customer
website string false The customers website
In [259]:
{
"customer_id": "00:14:22:01:23:45",
"profiles": [{
"source": "facebook",
"source_id": "87235872",
"link": "https://facebook.com/john.smith.478653",
}
In [260]:
with open('/home/wcmckee/local.json', 'r') as locj:
myjs = json.loads(locj.read())
In [261]:
thetraits = {"traits": {
"first_name": "John",
"last_name": "Smith",
"email": "john.smith@gmail.com",
"loyalty_level": "Elite Plus",
"loyalty_number": "AU8759342",
"birthdate": "1974-10-01",
"gender": "male",
"marketing_consent": True
}}
In [262]:
arge = arrow.get(thetraits['traits']['birthdate'], 'YYYY-MM-DD')
In [263]:
arge.strftime('%m')
Out[263]:
In [264]:
arge.strftime('%d')
Out[264]:
In [265]:
currentime.date()
Out[265]:
In [266]:
currentime.strftime('%m')
Out[266]:
In [267]:
import requests
In [268]:
unbreq = requests.get('https://api.giphy.com/v1/gifs/translate?api_key=123=unbirthday')
In [269]:
unbjs = unbreq.json()
In [270]:
unbjs['data']['images']['original']['url']
In [271]:
if arge.strftime('%m') == currentime.strftime('%m'):
print('it is your birthday month')
else:
print('it is not your birthday month')
In [272]:
if arge.strftime('%m-%d') == currentime.strftime('%d-%m'):
print('it is your birthday')
breq = requests.get('https://api.giphy.com/v1/gifs/random?api_key=123&tag=happy birthday&rating=G')
bjs = unbreq.json()
print(bjs['data']['images']['original']['url'])
else:
print('it is not your birthday')
unbreq = requests.get('https://api.giphy.com/v1/gifs/translate?api_key=123&s=happy unbirthday')
unbjs = unbreq.json()
print(unbjs['data']['images']['original']['url'])
In [273]:
breq = requests.get('https://api.giphy.com/v1/gifs/translate?api_key=123&s=birthday')
bjs = breq.json()
print(bjs['data']['images']['original']['url'])
In [274]:
arge.strftime('%m-%d') == currentime.strftime('%d-%m')
Out[274]:
In [275]:
print(arge.strftime('%m-%d'))
In [276]:
print(currentime.strftime('%d-%m'))
In [277]:
abs(int(arge.strftime('%Y')) - int(currentime.strftime('%Y')))
Out[277]:
In [278]:
thetraits['traits']['birthdate']
Out[278]:
In [279]:
tdelta = arge.strftime('%Y-%m-%d') - currentime.strftime('%Y-%m-%d')
In [280]:
from datetime import datetime
s1 = thetraits['traits']['birthdate']
s2 = currentime.strftime('%Y-%m-%d') # for example
FMT = '%Y-%m-%d'
tdelta = datetime.strptime(s2, FMT) - datetime.strptime(s1, FMT)
In [281]:
tdelta.days
Out[281]:
In [282]:
present = arrow.now()
paseve = present.shift(days=-7)
futur = present.shift(days=7)
In [283]:
rewardays = list()
In [284]:
for r in arrow.Arrow.span_range('day', paseve, futur):
#print(r.index)
myr = r[0]
print(myr.strftime('%m-%d'))
rewardays.append(myr.strftime('%m-%d'))
In [285]:
bdayrew = arge.strftime('%m-%d') in rewardays
In [286]:
if bdayrew == True:
print('its ya bday reward')
else:
print('its not ya bday reward')
In [287]:
def checkbirth(dob):
arge = arrow.get(dob, 'YYYY-MM-DD')
bdayrew = arge.strftime('%m-%d') in rewardays
if bdayrew == True:
return('its ya bday reward')
else:
return('its not ya bday reward')
In [288]:
checkbirth('1988-10-01')
Out[288]:
customer_id string true A customer identifier of customer. If you dont have one you can use the persons device mac or
email address instead.
longitude float true Longitude of the identified device
latitude float true Latitude of the identified device
seen_at string true A datetime when the device was last seen. In the format of a RFC 3339 datetime ( 2017-11-29T08:09:57Z )
In [28]:
"longitude": 151.20919,
"latitude": -33.88668,
"seen_at": "2017-11-29T08:09:57Z"
In [ ]:
In [29]:
def createlocation(email, longitude, latitude):
return({'email' : email, 'longitude' : longitude, 'latitude' : latitude})
In [52]:
createlocation('hammers@gmail.com', '151.20919', '-33.88668')
Out[52]:
In [53]:
import requests
In [ ]:
https://api.opencagedata.com/geocode/v1/json?q=41.40139%2C%202.12870&key=9943e82b6c974d878ff290540e9b9835&language=en&pretty=1
In [70]:
requrl = requests.get('https://api.opencagedata.com/geocode/v1/json?q=151.20919%2C%-33.88668&key=9943e82b6c974d878ff290540e9b9835&language=en&pretty=1')
In [71]:
requrl.json()
Out[71]:
In [49]:
import requests
url = 'https://maps.googleapis.com/maps/api/geocode/json'
params = {'sensor': 'false', 'address': 'Mountain View, CA'}
r = requests.get(url, params=params)
results = r.json()['results']
In [142]:
somejs = {
"customer_id": "00:14:22:01:23:45",
"profiles": [{
"source": "facebook",
"source_id": "87235872",
"link": "https://facebook.com/john.smith.478653",
},{
"source": "instagram",
"source_id": "245986569842",
"link": "https://instagram.com/johnsmith/",
},{
"source": "twitter",
"source_id": "72735729779824",
"link": "https://twitter.com/johnnysmiddy/",
},{
"source": "salesforce",
"source_id": "37461828371",
"link": "https://salesforce.com/customer/abc123"
}],
"traits": {
"first_name": "John",
"last_name": "Smith",
"email": "john.smith@gmail.com",
"loyalty_level": "Elite Plus",
"loyalty_number": "AU8759342",
"birthdate": "1974-08-01",
"gender": "male",
"marketing_consent": True
}
}
In [146]:
with open('/home/wcmckee/local.json', 'w') as locwr:
locwr.write(json.dumps(somejs))
In [147]:
with open('/home/wcmckee/local.json', 'r') as locrd:
locrd.read()
In [148]:
cat /home/wcmckee/local.json
In [153]:
creatime = {
"data": [
{
"created_time": "2017-12-08T01:08:57+0000",
"message": "Love this puzzle. One of my four coke puzzles",
"id": "820882001277849_1805191182846921"
},
{
"created_time": "2017-12-07T20:06:14+0000",
"message": "You need to add grape as a flavor for Coke in your freestyle machines.",
"id": "820882001277849_1804966026202770"
},
{
"created_time": "2017-12-07T01:29:12+0000",
"message": "Plz play the old commercial’s with the polar bears. Would be nice to see them this holiday",
"id": "820882001277849_1804168469615859"
}
]
}
In [150]:
automshrply = 'thank you for the comment. this is an auto responce to let you know we have seen it.'
In [239]:
commenturl = 'https://graph.facebook.com/{}/comments?message={}'.format(creatime['data'][crdata]['id'], automshrply)
In [240]:
commenturl
Out[240]:
In [163]:
for crdata in range(0, len(creatime['data'])):
print(creatime['data'][crdata])
print(creatime['data'][crdata]['id'])
#creatime['data']:
#print(creatime['data'])
automshrply = 'thank you for the comment. this is an auto responce to let you know we have seen it.'
commenturl = 'https://graph.facebook.com/{}/comments?message={}'.format(creatime['data'][crdata]['id'], automshrply)
print(commenturl)
In [72]:
reqfb = requests.get('https://api.meetup.com/self/calendar?photo-host=public&page=20&sig_id=58828502&sig=dcef242c3502d7e7e1f9129220507cb1f31ba3ec')
In [77]:
reqjs = (reqfb.json())
In [100]:
meetlen = len(reqjs)
In [101]:
print(meetlen)
In [118]:
for met in range(0, meetlen):
try:
print(reqjs[met])
print(reqjs[met]['venue'])
except KeyError:
#pass
print('error key not found')
In [78]:
print(reqjs[0]['venue'])
In [83]:
import arrow
In [84]:
timnow = arrow.now()
In [88]:
print(timnow.datetime)
In [98]:
def createfutloc(customer_id):
return(dict({'customer_id' : customer_id, 'name' : reqjs[0]['venue']['name'], 'address' : reqjs[0]['venue']['address_1'] + ' ' + reqjs[0]['venue']['city'] + ' ' + reqjs[0]['venue']['localized_country_name'], 'seen_at' : str(timnow.datetime)}))
In [99]:
createfutloc('hammers@gmail.com')
Out[99]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
{
"customer_id": "00:14:22:01:23:45",
"venue_id": "FJHKL334",
"name": "Level 1",
"address": "3 Drewberry Lane",
"seen_at": "2017-11-29T08:09:57Z"
}
In [79]:
reqjs[0]['venue']['']
In [108]:
import getmac
In [121]:
import sqlite3
In [122]:
connid = sqlite3.connect('identity.db')
In [123]:
c = connid.cursor()
# Create table
c.execute('''CREATE TABLE identify
(first_name, last_name, email, birthdate, gender, marketing_consent)''')
# Insert a row of data
c.execute("INSERT INTO identify VALUES ('{}','{}','{}', '{}', '{}', '{}')".format(first_name, last_name, email, birthdate, gender, marketing_consent))
# Save (commit) the changes
connid.commit()
# We can also close the connection if we are done with it.
# Just be sure any changes have been committed or they will be lost.
connid.close()
In [124]:
def createdb(namedb):
connid = sqlite3.connect('{}.db'.format(namedb))
c.execute('''CREATE TABLE identify
(first_name, last_name, email, birthdate, gender, marketing_consent)''')
connid.commit()
connid.close()
In [126]:
createdb('heo')
In [ ]:
In [127]:
def createsqprofile(first_name, last_name, email, marketing_consent, birthdate, gender):
connid = sqlite3.connect('identity.db')
c = connid.cursor()
c.execute("INSERT INTO identify VALUES ('{}','{}','{}', '{}', '{}', '{}')".format(first_name, last_name, email, birthdate, gender, marketing_consent))
connid.commit()
connid.close()
#db.insert({'first_name' : first_name, 'last_name' : last_name, 'email' : email, 'marketing_consent' : marketing_consent, 'birthdate' : birthdate, 'gender' : gender})
#return('Hello {} {}. Your email is {}. Marketing opt is {}. Your birthdate is {} and you are a {}'.format(first_name, last_name, email, marketing_consent, birthdate, gender))
return({'first_name' : first_name, 'last_name' : last_name, 'email' : email, 'marketing_consent' : marketing_consent, 'birthdate' : birthdate, 'gender' : gender})
In [128]:
createsqprofile('william', 'mckee', 'hammersmake@gmail.com', 'True', '1974-10-10', 'male')
Out[128]:
In [ ]:
In [ ]:
def mkdatabspro((first_name, last_name, email, marketing_consent, birthdate, gender):
In [ ]:
conn = sqlite3.connect('example.db')
c = conn.cursor()
c.execute("INSERT INTO identify VALUES ('{}','William','Mckee','hammer@gmail.com', '1974-08-01', 'male', 'True')".format(getmac.get_mac_address()))
conn.commit()
conn.close()