Skip to content

Commit

Permalink
redis removed and static file added
Browse files Browse the repository at this point in the history
  • Loading branch information
prabhakar267 committed Jul 10, 2016
1 parent 974d64c commit b51bc7a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
35 changes: 21 additions & 14 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,44 @@
# @Author: prabhakar
# @Date: 2016-07-09 21:06:19
# @Last Modified by: Prabhakar Gupta
# @Last Modified time: 2016-07-10 16:44:17
# @Last Modified time: 2016-07-10 19:04:06

import json
import requests.packages.urllib3
requests.packages.urllib3.disable_warnings()

import redis
from flask import Flask, abort, request
from flask.ext.cors import CORS

import github_email

EMAIL_FILE = "email_file"
app = Flask(__name__)
CORS(app)

@app.route("/", methods=['POST', 'GET'])
def main():
if request.method == 'GET':
abort(404)
else :
github_username = request.form.get('username').encode('ascii', 'ignore')
red = redis.StrictRedis(host='localhost', port=6379, db=0)
red_email = red.hget('email_list', github_username)

if red_email:
return "{0}".format(red_email)

x = github_email.get(github_username)
if x['success']:
email = x['email'][0]
else:
github_username = request.form.get('username').lower()

with open(EMAIL_FILE, 'r') as f:
email_dict = json.loads(f.read())

# check if the email was found earlier or not
if email_dict.get(github_username):
return email_dict[github_username]

response = github_email.get(github_username)
if response['success']:
email = response['email'][0]

# add email to be used in future
email_dict[github_username] = email
with open(EMAIL_FILE, 'w') as f:
json.dump(email_dict, f)

red.hset('email_list', github_username, email)
return "{0}".format(email)
else:
abort(404)
Expand Down
1 change: 1 addition & 0 deletions email_file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"sahildua2305": "[email protected]", "swati4star": "[email protected]", "prabhakar267": "[email protected]"}
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ Flask==0.10.1
Flask-Cors==2.1.2
github-email==0.0.4
gunicorn==19.6.0
redis==2.10.5

0 comments on commit b51bc7a

Please sign in to comment.