Skip to content

Commit

Permalink
many improvements ;-)
Browse files Browse the repository at this point in the history
  • Loading branch information
c7h committed Oct 31, 2014
1 parent e26744c commit e0c28f8
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 159 deletions.
84 changes: 84 additions & 0 deletions Tools/facebook_image_download_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
'''
Created on 16.08.2014
Download all the images from facebook-group users.
Ugglyy Hack, but works! (but is possible insecure - better run in in a save environment)
1. obtain an ACCESS TOKEN from Facebook:
https://developers.facebook.com/tools/explorer
2. set the 'target' GROUP ID
...just read it from the URI
wget needed!
@author: Christoph Gerneth
'''

from urllib2 import urlopen
import json
import os
import sys

# ----SETTINGS!----
group_id = 494276867251269
access_token = "CAACEdEose0cBAG0ZCic3bOPpgWazFZBeoq4nJ2oEh4YmJ0pz6DSLcmIWkZAvlR8Bllh7xLi9GupqZC7VtiZCInjETK3ZBBANsKEaDDn7lrZBiys0lcBbYWASZC5mbKF5kFk09ud4ZBOpffSKq5PViiZBMMfWrdunTR9pQsVIecgLTuQhLZCiq1ew3Ia8inwwqOTjQRTbZCDM9GPSjlwVABdJ967g"
WIDTH = 480
HEIGHT = 480
#--------END--------


class Member(object):
def __init__(self, name, id, admin=False):
self.name = name
self.id = id
self.admin = admin

def __repr__(self):
return "<User %s>" % self.name


def make_request(group_id, access_token):
url = "https://graph.facebook.com/v2.1/%i/members?access_token=%s" % (group_id, access_token)
print url

request = urlopen(url)
req_string = request.read()
return req_string

def create_members(group_json):
members = []
for member in group_json['data']:
mem = Member(member['name'], member['id'], admin=member['administrator'])
members.append(mem)
return members

def get_img_for_user(user_id, user_name=None, width=WIDTH, height=HEIGHT):
request_url = "https://graph.facebook.com/v2.1/%s/picture?width=%i&height=%s&redirect=false" % (user_id, width, height)
req = urlopen(request_url)
json_data = req.read()
di = json.loads(json_data)
url = di['data']['url']
img_name = unicode(user_name.lower().replace(" ", "_")+".jpg")
#build your download command
sys.stdout.write("foo %s" % img_name.encode('utf-8'))
command = 'wget %s -O %s' % (url.encode('utf-8'), img_name.encode('utf-8'))
print command
os.system(command)

try:
req_string = make_request(group_id, access_token)
except Exception, e:
print "[ERROR]", e
sys.exit()

user = json.loads(req_string)
members = []
members.extend(create_members(user))


print "found %i users in group" % len(members)
if raw_input("proceed? (y/n)") == "n":
sys.exit()

#aaaand download
for member in members:
get_img_for_user(member.id, member.name, 500)

Binary file removed database.sqlite
Binary file not shown.
138 changes: 0 additions & 138 deletions elo_rating.py

This file was deleted.

26 changes: 26 additions & 0 deletions facemash.wsgi
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os
import sys
import site

# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('/home/christoph/workspace/facemash/local/lib/python2.7/site-packages')

# Add the app's directory to the PYTHONPATH
# sys.path.append('/home/django_projects/MyProject')
# sys.path.append('/home/django_projects/MyProject/myproject')

# Activate your virtual env
activate_env=os.path.expanduser("/home/christoph/workspace/facemash/bin/activate_this.py")
execfile(activate_env, dict(__file__=activate_env))


import sys
from server import app

#Expand Python classes path with your app's path
sys.path.insert(0, "/home/christoph/workspace/facemash")

#Put logging code (and imports) here ...

#Initialize WSGI app object
application = app
13 changes: 11 additions & 2 deletions server.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# -*- coding: utf-8 -*-

'''
Created on 15.08.2014
@author: christoph
'''

from flask import Flask, render_template, session
from flask import Flask, render_template, session, url_for
from flask_bootstrap import Bootstrap
from flask_sqlalchemy import SQLAlchemy
from flask_script import Manager, Shell
Expand Down Expand Up @@ -44,6 +46,13 @@ class Player(db.Model):

def __repr__(self):
return "<Player %s>" % self.id

@property
def image(self):
fn = "face/%s" % self.imgurl
return url_for('static', filename=fn)



##Views

Expand All @@ -67,7 +76,7 @@ def mainpage():
winner = Player.query.get(winner_id)
looser = Player.query.get(looser_id)

print "[USER VOTED]: winner %s - looser: %s" % (winner, looser)
#print "[USER VOTED]: winner %s - looser: %s" % (winner, looser)
winner, looser = elo.match(winner, looser)
db.session.commit()

Expand Down
2 changes: 2 additions & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<link rel="icon" href="{{ url_for('static', filename="favicon.ico") }}" type="image/x-icon"></link>
<link rel="shortcut icon" href="{{ url_for('static', filename="favicon.ico") }}" type="image/x-icon"></link>

<meta name="mobile-web-app-capable" content="yes"></meta>


{% endblock %}

Expand Down
4 changes: 2 additions & 2 deletions templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<div class="row">
<div class="col-md-6">
<div class="thumbnail">
<img alt="Player1" src="/static/face/{{ players[0].imgurl }}" />
<img alt="Player1" src="{{ players[0].image }}" />
<div class="caption">
<h3>
<a href="/player/{{ players[0].id }}">{{ players[0].name }}</a>
Expand All @@ -30,7 +30,7 @@ <h3>
<div class="col-md-6">
<div class="thumbnail">

<img alt="Player2" src="/static/face/{{ players[1].imgurl }}" />
<img alt="Player2" src="{{ players[1].image }}" />
<div class="caption">
<h3>
<a href="/player/{{ players[1].id }}">{{ players[1].name }}</a>
Expand Down
2 changes: 1 addition & 1 deletion templates/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h3>
<div class="row clearfix">
<div class="col-md-8 column">
<div class="thumbnail">
<img class="img-rounded" alt="{{ player.name }}" src="/static/face/{{ player.imgurl }}" />
<img class="img-rounded" alt="{{ player.name }}" src="{{ player.image }}" />
</div>
</div>
<div class="col-md-4 column">
Expand Down
37 changes: 21 additions & 16 deletions templates/ranking.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,29 @@ <h3 class="text-center text-muted">
</tr>
</thead>
<tbody>

{% for player in players %}
<tr>
<td>

<tr>
<td>

{{ loop.index }}
</td>
<td>
{{ player.score }}
</td>
<td>
<a href="/player/{{ player.id }}">{{ player.name }}</a>
</td>
<td>
{{ player.matches }}
</td>
<td>
{{ player.wins }}
</td>
</tr>

</td>
<td>
{{ player.score }}
</td>
<td>
<a href="/player/{{ player.id }}">{{ player.name }}</a>
</td>
<td>
{{ player.matches }}
</td>
<td>
{{ player.wins }}
</td>
</tr>

{% endfor %}

</tbody>
Expand Down

0 comments on commit e0c28f8

Please sign in to comment.