Skip to content

Commit

Permalink
added Tip handling
Browse files Browse the repository at this point in the history
  • Loading branch information
akhilram committed Oct 16, 2015
1 parent a7ddbb9 commit 613d71b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
19 changes: 15 additions & 4 deletions json_to_mysql.py
Expand Up @@ -5,6 +5,7 @@
from models import Checkin
from models import Neighborhood
from models import Category
from models import Tip
import json
import decimal
from datetime import datetime
Expand Down Expand Up @@ -102,10 +103,20 @@ def save_checkins():
checkin.friday_count += number
elif day is 6:
checkin.saturday_count += number
checkin.save()
checkin.save()

def save_tips():
for tdata in iterate_file("tip", shortcircuit=True):
tip = Tip()
tip.business_id = tdata['business_id']
tip.text = tdata['text']
tip.user_id = tdata['user_id']
tip.date = datetime.strptime(tdata['date'], "%Y-%m-%d")
tip.likes = int(tdata['likes'])
tip.save()

def reset_database():
tables = (Business, Review, User, Checkin, Neighborhood, Category,)
tables = (Business, Review, User, Checkin, Neighborhood, Category, Tip,)
for table in tables:
# Nuke the Tables
try:
Expand All @@ -124,6 +135,6 @@ def reset_database():
save_businesses()
save_users()
save_checkins()
save_review()

save_reviews()
save_tips()

23 changes: 22 additions & 1 deletion models.py
Expand Up @@ -27,7 +27,7 @@ class Business(peewee.Model):
name = peewee.CharField()
full_address = peewee.CharField()
city = peewee.CharField()
state = peewee.CharField(max_length=2) # AZ
state = peewee.CharField(max_length=3) # XGL
latitude = peewee.CharField()
longitude = peewee.CharField()
stars = peewee.DecimalField() # star rating rounded to half-stars
Expand Down Expand Up @@ -136,3 +136,24 @@ class Checkin(peewee.Model):

class Meta:
database = db

class Tip(peewee.Model):
"""
{
'type': 'tip',
'text': (tip text),
'business_id': (encrypted business id),
'user_id': (encrypted user id),
'date': (date, formatted like '2012-03-14'),
'likes': (count),
}
"""
tip_id = peewee.PrimaryKeyField()
business_id = peewee.CharField()
text = peewee.TextField()
user_id = peewee.CharField()
date = peewee.DateField(formats="%Y-%m-%d") # '2012-03-14', %Y-%m-%d in strptime notation
likes = peewee.IntegerField()

class Meta:
database = db

0 comments on commit 613d71b

Please sign in to comment.