community-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgard...@apache.org
Subject svn commit: r1692984 - in /comdev/tools/events_list: admin.py models.py templates/groups/index.html urls.py views.py
Date Tue, 28 Jul 2015 04:12:56 GMT
Author: rgardler
Date: Tue Jul 28 04:12:55 2015
New Revision: 1692984

URL: http://svn.apache.org/r1692984
Log:
beginings of an import members feature, brings in members of a group. Currently just imports
Meetup ID - need to actually store useful data about each person

Modified:
    comdev/tools/events_list/admin.py
    comdev/tools/events_list/models.py
    comdev/tools/events_list/templates/groups/index.html
    comdev/tools/events_list/urls.py
    comdev/tools/events_list/views.py

Modified: comdev/tools/events_list/admin.py
URL: http://svn.apache.org/viewvc/comdev/tools/events_list/admin.py?rev=1692984&r1=1692983&r2=1692984&view=diff
==============================================================================
--- comdev/tools/events_list/admin.py (original)
+++ comdev/tools/events_list/admin.py Tue Jul 28 04:12:55 2015
@@ -1,9 +1,10 @@
 from django.contrib import admin
-from .models import Event, Group, Hashtag, Log
+from .models import Event, Group, Hashtag, Log, Person
 
 admin.site.register(Event)
 admin.site.register(Group)
 admin.site.register(Hashtag)
+admin.site.register(Person)
 
 admin.site.register(Log)
 

Modified: comdev/tools/events_list/models.py
URL: http://svn.apache.org/viewvc/comdev/tools/events_list/models.py?rev=1692984&r1=1692983&r2=1692984&view=diff
==============================================================================
--- comdev/tools/events_list/models.py (original)
+++ comdev/tools/events_list/models.py Tue Jul 28 04:12:55 2015
@@ -25,7 +25,6 @@ class Hashtag(models.Model):
 
 class Person(models.Model):
    meetupID =  models.BigIntegerField(verbose_name = "Meetups.com ID", unique=True)
-   lastMeetupVisit = models.DateTimeField()
     
 class Event(models.Model):
     name = models.CharField(max_length=200)

Modified: comdev/tools/events_list/templates/groups/index.html
URL: http://svn.apache.org/viewvc/comdev/tools/events_list/templates/groups/index.html?rev=1692984&r1=1692983&r2=1692984&view=diff
==============================================================================
--- comdev/tools/events_list/templates/groups/index.html (original)
+++ comdev/tools/events_list/templates/groups/index.html Tue Jul 28 04:12:55 2015
@@ -34,7 +34,7 @@
 	  <td>{{ group.state }}</td>
 	  <td>{{ group.country }}</td>
 	  {% if can_import %}
-  	    <td><a href="">Import Members</a></td>
+  	    <td><a href="{% url 'importMembers' group.id %}">Import Members</a></td>
           {% endif %}
 	</tr>
 	{% endfor %}

Modified: comdev/tools/events_list/urls.py
URL: http://svn.apache.org/viewvc/comdev/tools/events_list/urls.py?rev=1692984&r1=1692983&r2=1692984&view=diff
==============================================================================
--- comdev/tools/events_list/urls.py (original)
+++ comdev/tools/events_list/urls.py Tue Jul 28 04:12:55 2015
@@ -9,4 +9,5 @@ urlpatterns = [
     url(r'^importMeetups/$', views.importMeetups, name='importMeetups'),
 
     url(r'^groups$', views.groupIndex, name='groupIndex'),
+    url(r'^groups/(?P<group_id>[0-9]+)/importMembers/$', views.importMembers, name='importMembers'),
 ]

Modified: comdev/tools/events_list/views.py
URL: http://svn.apache.org/viewvc/comdev/tools/events_list/views.py?rev=1692984&r1=1692983&r2=1692984&view=diff
==============================================================================
--- comdev/tools/events_list/views.py (original)
+++ comdev/tools/events_list/views.py Tue Jul 28 04:12:55 2015
@@ -2,13 +2,20 @@ from django.conf import settings
 from django.shortcuts import get_object_or_404, render, redirect
 from django.http import HttpResponse
 from django.template import RequestContext, loader
-from events_list.models import Event, Group, Hashtag, Log
+from events_list.models import Event, Group, Hashtag, Log, Person
 from datetime import datetime, timedelta
 import json
 import logging
 import urllib2
 import sys
 
+# Note that this API key is *my* API key (rbowen) and if we start using
+# it more than a few dozen times an hour it's likely to get revoked.
+# Please play nice.
+# FIXME: make this a configuration value
+MEETUP_API_KEY = "3a7711454d145e404e531c2ee6f391d"
+
+
 logger = logging.getLogger(__name__)
 
 def index(request):
@@ -75,6 +82,37 @@ def _canImport():
         pass
     return can_import
 
+def importMembers(request, group_id):
+    group = get_object_or_404(Group, pk = group_id)
+
+    # Import members of a given group
+    log = Log()
+    log.description = "Members imported"
+    log.action_type = Log.EVENT_IMPORT
+    log.save()
+
+    url = "https://api.meetup.com/2/members?offset=0&format=json&group_id=18712511&photo-host=public&page=20&order=name&sig_id=148657742&key="
+ MEETUP_API_KEY
+    response = urllib2.urlopen(url)
+    result = response.read()
+
+    data = json.loads(result)
+    members = data['results']
+
+    for member in members:
+        try:
+            person = Person.objects.get(meetupID = member['id'])
+        except Person.DoesNotExist:
+            person = Person()
+
+        try:
+            person.meetupID = member['id']
+            person.save()
+        except:
+            print('Unable to save Person object: '), sys.exc_info()[0], sys.exc_info()[1]
+
+
+    return redirect('groupIndex')
+
 def importMeetups(request):
     # Import latest meetups from meetup.com, if we didn't import them within the last hour
     log = Log()
@@ -82,7 +120,6 @@ def importMeetups(request):
     log.action_type = Log.EVENT_IMPORT
     log.save()
 
-
     # get all the hashtags from the DB
     hashtags = Hashtag.objects.all().exclude(name = "Meetup")
 
@@ -97,15 +134,9 @@ def importMeetups(request):
 def _callMeetupsCom(hashtag):
     print "searching meetups.com for " + hashtag.name
 
-    # Note that this API key is *my* API key (rbowen) and if we start using
-    # it more than a few dozen times an hour it's likely to get revoked.
-    # Please play nice.
-    # FIXME: make this a configuration value
-    key = "3a7711454d145e404e531c2ee6f391d"
-
     # Radius is defined around Lexington, KY, but it's infinite radius, so
     # should work everywhere.
-    url = "https://api.meetup.com/2/open_events?&sign=true&photo-host=public&state=ky&city=lexington&country=usa&text="
+ hashtag.name + "&radius=10000&sign=true&key=" + key
+    url = "https://api.meetup.com/2/open_events?&sign=true&photo-host=public&state=ky&city=lexington&country=usa&text="
+ hashtag.name + "&radius=10000&sign=true&key=" + MEETUP_API_KEY
 
     print "Fetching meetups ..."
 
@@ -126,7 +157,7 @@ def _callMeetupsCom(hashtag):
     keys = groups.keys()
     keyarg = ",".join( keys )
     
-    group_url = "https://api.meetup.com/2/groups?&sign=true&photo-host=public&group_id="
+ keyarg + "&key=" + key
+    group_url = "https://api.meetup.com/2/groups?&sign=true&photo-host=public&group_id="
+ keyarg + "&key=" + MEETUP_API_KEY
 
     response = urllib2.urlopen( group_url )
     m = response.read()



Mime
View raw message