Commits

Anonymous committed 6bb2534

can now seed database with people at GA

Comments (0)

Files changed (16)

team/migrations/0001_initial.pyc

Binary file modified.

team/migrations/0002_auto__add_foursquareuser.pyc

Binary file modified.

team/migrations/0003_auto__add_venue.pyc

Binary file modified.

team/migrations/0004_auto__add_infectionevent.pyc

Binary file modified.

team/migrations/0005_auto__chg_field_infectionevent_infector__chg_field_infectionevent_user.py

+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        
+        # Changing field 'InfectionEvent.infector'
+        db.alter_column('team_infectionevent', 'infector_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['team.Foursquareuser']))
+
+        # Changing field 'InfectionEvent.user_infected'
+        db.alter_column('team_infectionevent', 'user_infected_id', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['team.Foursquareuser'], unique=True))
+
+
+    def backwards(self, orm):
+        
+        # Changing field 'InfectionEvent.infector'
+        db.alter_column('team_infectionevent', 'infector_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User']))
+
+        # Changing field 'InfectionEvent.user_infected'
+        db.alter_column('team_infectionevent', 'user_infected_id', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['auth.User'], unique=True))
+
+
+    models = {
+        'team.foursquareuser': {
+            'Meta': {'object_name': 'Foursquareuser'},
+            'fid': ('django.db.models.fields.CharField', [], {'max_length': '240'}),
+            'firstName': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'gender': ('django.db.models.fields.CharField', [], {'max_length': '1'}),
+            'homeCity': ('django.db.models.fields.CharField', [], {'max_length': '240'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'lastName': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'photo_url': ('django.db.models.fields.CharField', [], {'max_length': '2048'})
+        },
+        'team.infectionevent': {
+            'Meta': {'object_name': 'InfectionEvent'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'infectionplace': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['team.Venue']"}),
+            'infectiontime': ('django.db.models.fields.DateTimeField', [], {}),
+            'infector': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'uout'", 'to': "orm['team.Foursquareuser']"}),
+            'user_infected': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['team.Foursquareuser']", 'unique': 'True'})
+        },
+        'team.venue': {
+            'Meta': {'object_name': 'Venue'},
+            'address': ('django.db.models.fields.CharField', [], {'max_length': '400'}),
+            'city': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+            'fid': ('django.db.models.fields.CharField', [], {'max_length': '240'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'lat': ('django.db.models.fields.CharField', [], {'max_length': '90'}),
+            'lon': ('django.db.models.fields.CharField', [], {'max_length': '90'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '240'}),
+            'postalCode': ('django.db.models.fields.CharField', [], {'max_length': '12'}),
+            'state': ('django.db.models.fields.CharField', [], {'max_length': '200'})
+        }
+    }
+
+    complete_apps = ['team']

team/migrations/0005_auto__chg_field_infectionevent_infector__chg_field_infectionevent_user.pyc

Binary file added.

team/migrations/0006_auto__add_unique_foursquareuser_fid.py

+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        
+        # Adding unique constraint on 'Foursquareuser', fields ['fid']
+        db.create_unique('team_foursquareuser', ['fid'])
+
+
+    def backwards(self, orm):
+        
+        # Removing unique constraint on 'Foursquareuser', fields ['fid']
+        db.delete_unique('team_foursquareuser', ['fid'])
+
+
+    models = {
+        'team.foursquareuser': {
+            'Meta': {'object_name': 'Foursquareuser'},
+            'fid': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '240'}),
+            'firstName': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'gender': ('django.db.models.fields.CharField', [], {'max_length': '1'}),
+            'homeCity': ('django.db.models.fields.CharField', [], {'max_length': '240'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'lastName': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'photo_url': ('django.db.models.fields.CharField', [], {'max_length': '2048'})
+        },
+        'team.infectionevent': {
+            'Meta': {'object_name': 'InfectionEvent'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'infectionplace': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['team.Venue']"}),
+            'infectiontime': ('django.db.models.fields.DateTimeField', [], {}),
+            'infector': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'uout'", 'to': "orm['team.Foursquareuser']"}),
+            'user_infected': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['team.Foursquareuser']", 'unique': 'True'})
+        },
+        'team.venue': {
+            'Meta': {'object_name': 'Venue'},
+            'address': ('django.db.models.fields.CharField', [], {'max_length': '400'}),
+            'city': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+            'fid': ('django.db.models.fields.CharField', [], {'max_length': '240'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'lat': ('django.db.models.fields.CharField', [], {'max_length': '90'}),
+            'lon': ('django.db.models.fields.CharField', [], {'max_length': '90'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '240'}),
+            'postalCode': ('django.db.models.fields.CharField', [], {'max_length': '12'}),
+            'state': ('django.db.models.fields.CharField', [], {'max_length': '200'})
+        }
+    }
+
+    complete_apps = ['team']

team/migrations/0006_auto__add_unique_foursquareuser_fid.pyc

Binary file added.

team/migrations/__init__.pyc

Binary file modified.
     lastName = models.CharField(max_length=100)
     gender = models.CharField(max_length=1, choices = GENDERS)
     homeCity = models.CharField(max_length = 240)
-    fid = models.CharField(max_length = 240)
+    fid = models.CharField(max_length = 240, unique = True)
     photo_url = models.CharField(max_length = 2048)
 
+    def __unicode__(self):
+        return "%s %s" % (self.firstName, self.lastName)
+
+    def from_api(self, d):
+        gender_map = { 'male' : 'm', 'female': 'f' }
+        self.firstName = d['firstName']
+        try:
+            self.lastName = d['lastName']
+        except KeyError:
+            pass
+
+        self.gender = gender_map[d['gender']]
+        self.homeCity = d['homeCity']
+        self.photo_url = d['photo']
+        self.fid = d['id']
+
+
+
 class Venue(models.Model):
     fid = models.CharField(max_length = 240)
     name = models.CharField(max_length = 240)
 
 
 class InfectionEvent(models.Model):
-    infector = models.ForeignKey(User, related_name = 'uout')
-    user_infected = models.OneToOneField(User)
+    infector = models.ForeignKey(Foursquareuser, related_name = 'uout')
+    user_infected = models.OneToOneField(Foursquareuser)
     infectiontime = models.DateTimeField()
     infectionplace = models.ForeignKey(Venue)

team/models.pyc

Binary file modified.
 # Create your views here.
 #from lib.foursquare import foursquare
 import foursquare2 as foursquare
+from django.http import HttpResponse
 from team.models import *
 from django.views.generic.simple import direct_to_template
 
 venue = '4c5c076c7735c9b6af0e8b72'
 
 def index(request):
-    here = repr(fs.venues_herenow(venue))
-    return direct_to_template(request, 'index.html', {'here':here})
+    here = fs.venues_herenow(venue)
+    items = here.items()[1][1]['hereNow']['items']
+    users = [i['user'] for i in items]
+    return direct_to_template(request, 'index.html', {'here':repr(users)})
+
+def get_ga(request):
+    here = fs.venues_herenow(venue)
+    items = here.items()[1][1]['hereNow']['items']
+    users = [i['user'] for i in items]
+
+    for rawuser in users:
+        try:
+            u = Foursquareuser()
+            u.from_api(rawuser)
+            u.save()
+        except Exception:
+            pass
+    return HttpResponse('hey')
+
 
 def infect():
     #for "list of foursquare IDs":

team/views.pyc

Binary file modified.
Binary file modified.
     # (r'^Fourskill/', include('Fourskill.foo.urls')),
     url(r'^$', "team.views.index", name="team-index"),
     url(r'^infected/', "team.views.infected", name="team-infected"),
+    url(r'^getGA/$', 'team.views.get_ga', name = 'team-get-ga'),
     # Uncomment the admin/doc line below to enable admin documentation:
     # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
 
Binary file modified.