-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 287beac
Showing
39 changed files
with
10,372 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
*.pyc | ||
codes.csv | ||
.idea | ||
run.py | ||
flask |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# chooseeats | ||
app for eating with friends | ||
|
||
source code for www.chooseeats.com |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from flask import Flask | ||
from flask.ext.sqlalchemy import SQLAlchemy | ||
|
||
app = Flask(__name__) | ||
app.config.from_object('config') | ||
db = SQLAlchemy(app) | ||
|
||
from app import views, models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
import foursquare | ||
from datetime import datetime | ||
import csv | ||
import pandas as pd | ||
import numpy as np | ||
|
||
# Set client & secret code | ||
redir = 'http://nickof4.pythonanywhere.com/auth' | ||
redir = 'http://localhost:5000/auth' | ||
|
||
with open('codes.csv', 'rb') as csvfile: | ||
codesf = csv.DictReader(csvfile) | ||
for row in codesf: | ||
codes = row | ||
|
||
cid = codes['client'] | ||
csc = codes['secret'] | ||
|
||
# Make a auth class | ||
class fourauther(object): | ||
def __init__(self): | ||
# Initiate client | ||
self.auther = foursquare.Foursquare(client_id = cid, | ||
client_secret = csc, | ||
redirect_uri = redir) | ||
|
||
# Make auth url | ||
def aurl(self): | ||
return self.auther.oauth.auth_url() | ||
|
||
# Exchange code for token | ||
def exch(self, code): | ||
return self.auther.oauth.get_token(str(code)) | ||
|
||
# Infograbber | ||
class usrinfo(object): | ||
# initialize | ||
def __init__(self, token): | ||
# Initiate Client | ||
self.client = foursquare.Foursquare(client_id = cid, | ||
client_secret = csc, | ||
redirect_uri = redir, | ||
access_token = token) | ||
|
||
# Get Categories | ||
def getFoodCats(self): | ||
# Grab food categories | ||
fcats = self.client.venues.categories()['categories'][3]['categories'] | ||
|
||
# Pull out id and name | ||
rtypes = [] | ||
for cat in fcats: | ||
rtypes.append([cat['name'], cat['id']]) | ||
rtypes = pd.DataFrame(rtypes, columns = ['rname', 'rid']) | ||
|
||
return rtypes | ||
|
||
# Get User info | ||
def getUserInfo(self): | ||
uinfo = self.client.users()['user'] | ||
|
||
return uinfo | ||
|
||
# Get friends | ||
def getFriends(self): | ||
# Grab data | ||
friends = self.getUserInfo()['friends']['groups'] | ||
|
||
# Loop and get | ||
reflist = [] | ||
for group in friends: | ||
# Get friends in group | ||
flist = group['items'] | ||
|
||
# Get friend info | ||
for f in flist: | ||
purl = '%s128x128%s' % (f['photo']['prefix'], | ||
f['photo']['suffix']) | ||
churl = '/results?fid=%s' % (f['id']) | ||
reflist.append([int(f['id']), | ||
f['firstName'], | ||
f['lastName'], | ||
purl, | ||
churl]) | ||
|
||
# Convert to pandas and return | ||
cnames = ['id', 'firstname', 'lastname', 'photo', 'churl'] | ||
flist = pd.DataFrame(reflist, columns = cnames) | ||
return flist | ||
|
||
# Get Checkins | ||
def getChecks(self): | ||
|
||
# Grab data | ||
checkins = self.client.users.checkins()['checkins']['items'] | ||
|
||
# Venue data | ||
ventype = self.getFoodCats() | ||
|
||
# Take out info we want | ||
cattime = [] | ||
for check in checkins: | ||
# Get category | ||
cat = check['venue']['categories'][0]['name'] | ||
catid = check['venue']['categories'][0]['id'] | ||
|
||
cattime.append([check['createdAt'], cat, catid, | ||
check['like'].conjugate()]) | ||
|
||
# Convert to dataframe | ||
cnames = ['time', 'type', 'rid', 'like'] | ||
cattime = pd.DataFrame(cattime, columns = cnames) | ||
|
||
# Only return food places | ||
cattime = cattime[cattime.rid.isin(ventype.rid)] | ||
|
||
# Summarise by food type | ||
cattime = cattime.groupby('type', as_index = False).agg({'like':np.mean, | ||
'time':max}) | ||
|
||
# Format and sort | ||
def difftime(oldtime): | ||
diff = datetime.now() - datetime.fromtimestamp(oldtime) | ||
return int(diff.days) | ||
|
||
def fortime(timest): | ||
newt = datetime.fromtimestamp(timest).strftime('%m-%d-%Y') | ||
return newt | ||
|
||
cattime['tsince'] = cattime.time.apply(difftime) | ||
cattime['lastti'] = cattime.time.apply(fortime) | ||
cattime = cattime.sort(['tsince', 'like'], ascending = [False, False]) | ||
|
||
# Return | ||
return cattime | ||
|
||
# Analysis class | ||
class analyze(object): | ||
def __init__(self): | ||
pass | ||
|
||
# Time calcer | ||
def timeFinder(self, times): | ||
# Calculate | ||
tscore = times.mean(axis=1) * (times.max(axis=1) / times.min(axis=1)) | ||
return tscore | ||
|
||
# Compare Histories | ||
def compHists(self, usr1, usr2): | ||
# Inner join to get only restaurants both have been to | ||
matched = usr1.merge(usr2, on = 'type') | ||
|
||
# Calculate mean time visited and like percentage | ||
matched['meantime'] = matched[['time_x', 'time_y']].mean(axis = 1) | ||
matched['meanlike'] = matched[['like_x', 'like_y']].mean(axis = 1) | ||
matched['recenyscr'] = self.timeFinder(matched[['time_x', 'time_y']]) | ||
matched['reccoscr'] = matched.recenyscr * matched.meanlike | ||
|
||
# Sort by time then likes | ||
matched.sort('reccoscr') | ||
|
||
return matched |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from flask.ext.wtf import Form | ||
from wtforms import StringField | ||
from wtforms.validators import DataRequired | ||
|
||
class userForm(Form): | ||
userid = StringField('userID', validators=[DataRequired()]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from app import db | ||
|
||
class User(db.Model): | ||
id = db.Column(db.Integer, primary_key=True) | ||
firstname = db.Column(db.String(64), index=True, unique=False) | ||
lastname = db.Column(db.String(64), index=True, unique=False) | ||
userid = db.Column(db.Integer, index=True, unique=True) | ||
token = db.Column(db.String(120), index=True, unique=True) | ||
|
||
def __repr__(self): | ||
return '<User %r>' % (self.firstname) |
Oops, something went wrong.