-
Notifications
You must be signed in to change notification settings - Fork 37
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
Benjamin Cutler
committed
Oct 14, 2012
0 parents
commit 3cfb9d0
Showing
55 changed files
with
5,241 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,3 @@ | ||
*.mo | ||
*.pyc | ||
*.swp |
Empty file.
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,14 @@ | ||
from django.contrib import admin | ||
import donations.tracker.models | ||
|
||
admin.site.register(donations.tracker.models.Challenge) | ||
admin.site.register(donations.tracker.models.ChallengeBid) | ||
admin.site.register(donations.tracker.models.Choice) | ||
admin.site.register(donations.tracker.models.ChoiceBid) | ||
admin.site.register(donations.tracker.models.ChoiceOption) | ||
admin.site.register(donations.tracker.models.Donation) | ||
admin.site.register(donations.tracker.models.Donor) | ||
admin.site.register(donations.tracker.models.Event) | ||
admin.site.register(donations.tracker.models.Prize) | ||
admin.site.register(donations.tracker.models.SpeedRun) | ||
admin.site.register(donations.tracker.models.UserProfile) |
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,148 @@ | ||
import urllib | ||
import urllib2 | ||
import cookielib | ||
import httplib | ||
import HTMLParser as htmllib | ||
import time | ||
import datetime | ||
from donations.tracker.models import * | ||
from decimal import Decimal | ||
|
||
cj = cookielib.CookieJar() | ||
|
||
class Error: | ||
def __init__(self, msg='Unknown'): | ||
self.msg = msg | ||
def __unicode__(self): | ||
return u'Chipin Error: ' + self.msg | ||
|
||
def hascookie(jar, name): | ||
for cookie in jar: | ||
if cookie.name == name: return True | ||
return False | ||
|
||
def dumpcookies(jar): | ||
for cookie in jar: | ||
print cookie.name + '=' + cookie.value | ||
|
||
def login(login, password): | ||
global cj | ||
params = urllib.urlencode((('loginEmail', login), ('loginPassword', password))) | ||
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) | ||
request = urllib2.Request('http://www.chipin.com/loginsubmit') | ||
request.add_data(params) | ||
response = opener.open(request) | ||
cj.extract_cookies(response, request) | ||
response = opener.open('http://www.chipin.com/dashboard') | ||
redirect = response.geturl() | ||
if redirect != 'http://www.chipin.com/dashboard': | ||
return False | ||
return True | ||
|
||
class ChipinParser(htmllib.HTMLParser): | ||
def __init__(self): | ||
htmllib.HTMLParser.__init__(self) | ||
self.data = {} | ||
self.intable = False | ||
self.inrow = False | ||
self.incolumn = False | ||
self.added = False | ||
def handle_starttag(self, tag, attrs): | ||
if tag == 'table': | ||
attrs = dict(attrs) | ||
if attrs.get('id', '') == 'contributortable': | ||
self.intable = True | ||
elif self.inrow and tag == 'td': | ||
self.incolumn = True | ||
self.column += 1 | ||
elif self.intable and tag == 'tr': | ||
self.inrow = True | ||
self.row = [''] * 8 | ||
self.column = -1 | ||
def handle_endtag(self, tag): | ||
if tag == 'table': | ||
self.intable = False | ||
elif tag == 'td': | ||
self.incolumn = False | ||
elif tag == 'tr' and self.inrow: | ||
self.inrow = False | ||
name = self.row[0] | ||
email = self.row[1] | ||
comment = self.row[3] | ||
timestamp = self.row[4][:-3] | ||
amount = self.row[5] | ||
id = timestamp + email | ||
self.data[id] = {'name': name, 'email': email, 'comment': comment, 'timestamp': timestamp, 'amount': amount, 'id': id} | ||
try: | ||
long(timestamp) | ||
except ValueError: | ||
print self.row | ||
print self.data[id] | ||
raise | ||
def handle_data(self, data): | ||
if self.incolumn: | ||
self.row[self.column] += data | ||
self.added = True | ||
|
||
|
||
def merge(event, id): | ||
global cj | ||
if not hascookie(cj, 'JSESSIONID'): | ||
raise Error('Not logged in') | ||
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) | ||
r = opener.open('http://www.chipin.com/contributors/private/id/' + id) | ||
data = r.read() | ||
new = 0 | ||
updated = 0 | ||
donors = {} | ||
donations = {} | ||
for donation in Donation.objects.filter(event=event): | ||
donations[donation.domainId] = donation | ||
for donor in Donor.objects.all(): | ||
donors[donor.email] = donor | ||
print len(donors) | ||
#data = open("sgdq2012.htm").read() | ||
parser = ChipinParser() | ||
parser.feed(data) | ||
for id,row in parser.data.items(): | ||
if not id in donations: | ||
new += 1 | ||
print "New Donation: " + str(row) | ||
donation = Donation() | ||
donation.event = event | ||
donation.timereceived = datetime.datetime.utcfromtimestamp(long(row['timestamp'])) | ||
if row['email'] not in donors: | ||
donor = Donor() | ||
donor.email = row['email'] | ||
donor.firstname = row['name'].split()[0] | ||
donor.lastname = ' '.join(row['name'].split()[1:]) | ||
donor.save() | ||
donors[row['email']] = donor | ||
else: | ||
donor = donors[row['email']] | ||
donation.donor = donor | ||
donation.domainId = id | ||
donation.domain = 'CHIPIN' | ||
donation.comment = row['comment'] | ||
donation.commentstate = 'PENDING' | ||
donation.amount = Decimal(row['amount']) | ||
if not donation.comment or donation.amount < Decimal(1): | ||
donation.readstate = 'IGNORED' | ||
else: | ||
donation.readstate = 'PENDING' | ||
if not donation.comment: | ||
donation.bidstate = 'IGNORED' | ||
else: | ||
donation.bidstate = 'PENDING' | ||
donation.save() | ||
elif not donations[id].comment and row['comment']: | ||
updated += 1 | ||
print "Updated Donation: " + str(row) | ||
donation = donations[id] | ||
donation.comment = row['comment'] | ||
donation.readstate = 'PENDING' | ||
donation.commentstate = 'PENDING' | ||
donation.bidstate = 'PENDING' | ||
donation.save() | ||
return len(parser.data),new,updated | ||
|
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,20 @@ | ||
from django import forms | ||
from django.contrib.auth.models import User | ||
from django.utils.translation import ugettext as _ | ||
import re | ||
|
||
class UsernameForm(forms.Form): | ||
username = forms.CharField( | ||
max_length=255, | ||
widget=forms.TextInput(attrs={'class': 'required username'})) | ||
|
||
def clean_username(self): | ||
if 'username' in self.cleaned_data: | ||
username = self.cleaned_data['username'] | ||
if not re.match(r'^[a-zA-Z0-9_]+$', username): | ||
raise forms.ValidationError(_("Usernames can only contain letters, numbers, and the underscore")) | ||
if username[:10]=='openiduser': | ||
raise forms.ValidationError(_("Username may not start with 'openiduser'")) | ||
if User.objects.filter(username=username).count() > 0: | ||
raise forms.ValidationError(_("Username already in use")) | ||
return self.cleaned_data['username'] |
Oops, something went wrong.