Skip to content

Commit ca4a2b7

Browse files
author
Liam
committed
Merge pull request #72 from tenex/lb/remove-pythonic-cobwebs
Remove old Python stuff
2 parents b0687bb + 7227192 commit ca4a2b7

File tree

8 files changed

+57
-173
lines changed

8 files changed

+57
-173
lines changed

app/config.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

app/github_contributions.py

Lines changed: 3 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,5 @@
1-
from flask import Flask, render_template
2-
from flask.ext.pymongo import PyMongo, ASCENDING, DESCENDING
3-
from tools import jsonify
4-
from datetime import datetime, timezone
5-
import dateutil.parser
6-
import time
7-
import math
8-
1+
from flask import Flask
2+
from flask.ext.pymongo import PyMongo
93
app = Flask(__name__)
10-
app.config.from_pyfile('config.py')
4+
app.config['MONGO_DBNAME'] = 'contributions'
115
mongo = PyMongo(app)
12-
13-
PAGE_SIZE = 50
14-
15-
@app.route('/')
16-
def index():
17-
return app.send_static_file('index.html')
18-
19-
@app.route('/stats')
20-
def stats():
21-
c = mongo.db.contributions
22-
latest_event = c.find().sort('created_at', DESCENDING).limit(1)
23-
latest_event = [e['created_at'] for e in latest_event].pop()
24-
latest_event_dt = dateutil.parser.parse(latest_event)
25-
latest_event_age = datetime.now(timezone.utc) - latest_event_dt
26-
latest_event_age = int(latest_event_age.total_seconds())
27-
summary = {
28-
"eventCount": c.count(),
29-
"latestEvent": latest_event,
30-
"latestEventAge": latest_event_age
31-
}
32-
return jsonify(**summary)
33-
34-
@app.route('/error')
35-
def error():
36-
time.sleep(3)
37-
raise RuntimeError('Here is an error, as you requested.')
38-
39-
@app.errorhandler(Exception)
40-
def runtime_error_handler(err):
41-
err_data = {
42-
'error': str(err)
43-
}
44-
return jsonify(err_data), 500
45-
46-
@app.route('/user/<username>')
47-
def user(username):
48-
collection = mongo.db.contributions
49-
criteria = {
50-
'_user_lower': username.lower(),
51-
}
52-
repos = collection.find(criteria)
53-
repos = repos.distinct('repo')
54-
repos.sort(key=str.lower)
55-
56-
event_count = collection.find(criteria).count()
57-
58-
summary = {
59-
"username": username,
60-
"eventCount": event_count,
61-
"repos": repos,
62-
}
63-
return jsonify(**summary)
64-
65-
@app.route('/user/<username>/events')
66-
@app.route('/user/<username>/events/<int:page>')
67-
def events(username, page=1):
68-
collection = mongo.db.contributions
69-
criteria = {
70-
'_user_lower': username.lower(),
71-
}
72-
73-
skip = (page-1) * PAGE_SIZE
74-
#total_pages = math.ceil(float(total) / PAGE_SIZE)
75-
76-
events = collection.find(criteria)
77-
events = events.sort("created_at", DESCENDING)
78-
events = events.skip(skip).limit(PAGE_SIZE)
79-
events = list(events)
80-
events = {
81-
"events": events,
82-
"start": skip+1,
83-
"end": skip+len(events),
84-
"currentPage": page,
85-
"size": len(events)
86-
}
87-
return jsonify(**events)

app/tools.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

manage

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,12 @@ def _make_context():
1515
)
1616

1717
manager = Manager(app)
18-
manager.add_command('runserver', Server(host='0.0.0.0', use_debugger=True))
1918
manager.add_command('shell', Shell(
2019
make_context=_make_context,
2120
use_ipython=True,
2221
banner='GitHub Contributions Shell'
2322
))
2423

25-
@manager.command
26-
def usernames():
27-
""" generate list of distinct usernames from transformed data
28-
"""
29-
import glob
30-
import gzip
31-
import json
32-
33-
users = set()
34-
files = list(glob.glob(os.path.join(
35-
os.environ['GHC_TRANSFORMED_PATH'], '*.json.gz')))
36-
print("looking in", len(files), "files")
37-
for ix, path in enumerate(files):
38-
with gzip.open(path, 'rt', encoding='utf-8') as f:
39-
events = (json.loads(line) for line in f)
40-
users |= set((e.get('_user_lower') for e in events))
41-
print(ix, "\t", len(files))
42-
43-
users = sorted(users)
44-
45-
with open('users.txt', 'wt') as f:
46-
for u in users: print(u, file=f)
47-
48-
print("there are", len(users), "users")
49-
5024
@manager.command
5125
def ensure_indexes():
5226
""" ensure contributions are indexed

requirements-w32.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@ filelock==1.0.3
22
Flask==0.10.1
33
Flask-PyMongo==0.4.0
44
Flask-Script==2.0.5
5-
itsdangerous==0.24
6-
Jinja2==2.7.3
75
MarkupSafe==0.23
86
pymongo==3.1.1
97
python-dateutil==2.4.2
108
requests==2.7.0
119
six==1.9.0
1210
termcolor==1.1.0
13-
Werkzeug==0.10.4
1411
rollbar=0.11.2

requirements.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,10 @@ filelock==1.0.3
22
Flask==0.10.1
33
Flask-PyMongo==0.4.0
44
Flask-Script==2.0.5
5-
itsdangerous==0.24
6-
Jinja2==2.7.3
7-
MarkupSafe==0.23
85
pymongo==3.1.1
96
python-dateutil==2.4.2
107
python-rapidjson==0.0.6
118
requests==2.7.0
129
six==1.9.0
1310
termcolor==1.1.0
14-
uWSGI==2.0.11.2
15-
Werkzeug==0.10.4
1611
rollbar==0.11.2

util/mongo/find-duplicate-events.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
// This shouldn't ever need to be run unless the existing data needs re-importing
22
// Takes 40 minutes to clear 10 records :(
33
db.contributions.aggregate(
4-
[
5-
{
6-
"$match": {
7-
"_event_id": { "$exists" : true },
8-
},
9-
},
10-
{
11-
"$group": {
12-
"_id": { "_event_id": "$_event_id" },
13-
"uniqueIds": { "$push": "$_id" },
14-
"count": { "$sum": 1 },
15-
},
16-
},
17-
{
18-
"$match": {
19-
"count": { "$gt": 1 },
20-
}
21-
},
22-
{
23-
$out : "duplicates",
24-
}
25-
],
4+
[
265
{
27-
"allowDiskUse": true,
6+
"$match": {
7+
"_event_id": { "$exists" : true }
8+
},
9+
},
10+
{
11+
"$group": {
12+
"_id": { "_event_id": "$_event_id" },
13+
"uniqueIds": { "$push": "$_id" },
14+
"count": { "$sum": 1 }
15+
},
16+
},
17+
{
18+
"$match": {
19+
"count": { "$gt": 1 }
20+
}
21+
},
22+
{
23+
$out : "duplicates"
2824
}
25+
],
26+
{
27+
"allowDiskUse": true
28+
}
2929
);
3030
// .forEach(function(doc) {
3131
// doc.uniqueIds.shift();

util/usernames

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python3
2+
from __future__ import print_function
3+
import os
4+
import sys
5+
import glob
6+
import gzip
7+
import json
8+
9+
10+
def usernames():
11+
""" generate list of distinct usernames from transformed data
12+
"""
13+
users = set()
14+
files = list(glob.glob(os.path.join(
15+
os.environ['GHC_TRANSFORMED_PATH'], '*.json.gz')))
16+
print("looking in", len(files), "files")
17+
for ix, path in enumerate(files):
18+
with gzip.open(path, 'rt', encoding='utf-8') as f:
19+
events = (json.loads(line) for line in f)
20+
users |= set((e.get('_user_lower') for e in events))
21+
print(ix, "\t", len(files))
22+
23+
users = sorted(users)
24+
25+
with open('users.txt', 'wt') as f:
26+
for u in users: print(u, file=f)
27+
28+
print("there are", len(users), "users")
29+
30+
if __name__=='__main__':
31+
usernames()

0 commit comments

Comments
 (0)