diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/hackathon_starter/hackathon/forms.py b/hackathon_starter/hackathon/forms.py index fa57d39..1980e8b 100644 --- a/hackathon_starter/hackathon/forms.py +++ b/hackathon_starter/hackathon/forms.py @@ -9,3 +9,6 @@ class UserForm(forms.ModelForm): class Meta: model = User fields = ('username', 'email', 'password') + +class UploadFileForm(forms.Form): + file = forms.FileField() diff --git a/hackathon_starter/hackathon/templates/hackathon/base.html b/hackathon_starter/hackathon/templates/hackathon/base.html index ac32729..372066a 100644 --- a/hackathon_starter/hackathon/templates/hackathon/base.html +++ b/hackathon_starter/hackathon/templates/hackathon/base.html @@ -1,61 +1,72 @@ +{% load staticfiles %} + + +{% load bootstrap3 %} + +{% bootstrap_css %} +{% bootstrap_javascript %} - + Django Hackathon Starter - + - - - - + \ No newline at end of file diff --git a/hackathon_starter/hackathon/templates/hackathon/login.html b/hackathon_starter/hackathon/templates/hackathon/login.html old mode 100644 new mode 100755 index 12d63e9..d7b25f8 --- a/hackathon_starter/hackathon/templates/hackathon/login.html +++ b/hackathon_starter/hackathon/templates/hackathon/login.html @@ -26,26 +26,6 @@

Login

- - - Sign in with Twitter - - - - Sign in with Instagram - - - - Sign in with Tumblr - - - - Sign in with Github - - - - Sign in with LinkedIn - Sign in with Facebook @@ -54,14 +34,6 @@ Sign in with Google+ - - - Sign in with Dropbox - - - - Sign in with Foursquare -
diff --git a/hackathon_starter/hackathon/templates/hackathon/upload_csv.html b/hackathon_starter/hackathon/templates/hackathon/upload_csv.html new file mode 100644 index 0000000..2f806e7 --- /dev/null +++ b/hackathon_starter/hackathon/templates/hackathon/upload_csv.html @@ -0,0 +1,27 @@ + + + + + Title + + + +{% include 'hackathon/base.html' %} + +{% load static %} + +{% block content %} +
+ {% csrf_token %} + {{ form }} + +
+{% endblock %} + + \ No newline at end of file diff --git a/hackathon_starter/hackathon/templates/hackathon/view_csv_requests.html b/hackathon_starter/hackathon/templates/hackathon/view_csv_requests.html new file mode 100644 index 0000000..e8db8fa --- /dev/null +++ b/hackathon_starter/hackathon/templates/hackathon/view_csv_requests.html @@ -0,0 +1,31 @@ + + + + + Title + + + +{% include 'hackathon/base.html' %} + +{% load static %} + +{% block content %} +{% for r in requests %} +
+{% for key, value in r.items %} +

{{key}}: {{ value }}

+{% endfor %} +
+
+{% endfor %} +{% endblock %} + + \ No newline at end of file diff --git a/hackathon_starter/hackathon/urls.py b/hackathon_starter/hackathon/urls.py index f6d6745..c47de47 100644 --- a/hackathon_starter/hackathon/urls.py +++ b/hackathon_starter/hackathon/urls.py @@ -1,59 +1,62 @@ from django.conf.urls import patterns, url, include from rest_framework.routers import DefaultRouter -from hackathon import views +import views router = DefaultRouter() router.register(r'snippets', views.SnippetView) urlpatterns = patterns('', - url(r'^', include(router.urls)), - url(r'^register/$', views.register, name='register'), - url(r'^login/$', views.user_login, name='login'), - url(r'^logout/$', views.user_logout, name='logout'), - url(r'^api/$', views.api_examples, name='api'), - url(r'^steam/$', views.steam, name='steam'), - url(r'^steamDiscountedGames/$', views.steamDiscountedGames, name='steamDiscountedGames'), - url(r'^githubResume/$', views.githubResume, name='githubResume'), - url(r'^githubUser/$', views.githubUser, name='githubUser'), - url(r'^githubTopRepositories/$', views.githubTopRepositories, name='githubTopRepositories'), - url(r'^tumblr/$', views.tumblr, name='tumblr'), - url(r'^linkedin/$', views.linkedin, name='linkedin'), - url(r'^twilio/$', views.twilio, name='twilio'), - url(r'^instagram/$', views.instagram, name='instagram'), - url(r'^instagram_login/$', views.instagram_login, name='instagram_login'), - url(r'^instagramUser/$', views.instagramUser, name='instagramUser'), - url(r'^instagramMediaByLocation/$', views.instagramMediaByLocation, name='instagramMediaByLocation'),# - url(r'^instagramUserMedia/$', views.instagramUserMedia, name='instagramUserMedia'), - url(r'^twitter/$', views.twitter, name='twitter'), - url(r'^twitterTweets/$', views.twitterTweets, name='twitterTweets'), - url(r'^tumblr_login/$', views.tumblr_login, name='tumblr_login'), - url(r'^twitter_login/$', views.twitter_login, name='twitter_login'), - url(r'^github_login/$', views.github_login, name='github_login'), - url(r'^linkedin_login/$', views.linkedin_login, name='linkedin_login'), - url(r'^facebook_login/$', views.facebook_login, name='facebook_login'), - url(r'^facebook/$', views.facebook, name='facebook'), - url(r'^google_login/$', views.google_login, name='google_login'), - url(r'^google/$', views.googlePlus, name='googlePlus'), - url(r'^dropbox_login/$', views.dropbox_login, name='dropbox_login'), - url(r'^dropbox/$', views.dropbox, name='dropbox'), - url(r'^dropboxSearchFile/$', views.dropboxSearchFile, name='dropboxSearchFile'), - url(r'^foursquare_login/$', views.foursquare_login, name='foursquare_login'), - url(r'^foursquare/$', views.foursquare, name='foursquare'), - url(r'^quandlSnp500/$', views.quandlSnp500, name='quandlsnp500'), - url(r'^quandlNasdaq/$', views.quandlNasdaq, name='quandlnasdaq'), - url(r'^quandlNasdaqdiff/$', views.quandlNasdaqdiff, name='quandlnasdaqdiff'), - url(r'^quandlDowJones/$', views.quandlDowJones, name='quandldowjones'), - url(r'^quandlstocks/$', views.quandlstocks, name='quandlstocks'), - url(r'^quandlapple/$', views.quandlapple, name='quandlapple'), - url(r'^quandlapplediff/$', views.quandlapplediff, name='quandlapplediff'), - url(r'^quandlDowJonesdiff/$', views.quandlDowJonesdiff, name='quandldowjonesdiff'), - url(r'^quandlSnp500diff/$', views.quandlSnp500diff, name='quandlsnp500diff'), - url(r'^nytimespop/$', views.nytimespop, name='nytimespop'), - url(r'^nytimestop/$', views.nytimestop, name='nytimestop'), - url(r'^nytimesarticles/$', views.nytimesarticles, name='nytimesarticles'), - url(r'^meetup/$', views.meetup, name='meetup'), - url(r'^meetupToken/$', views.meetupToken, name='meetupToken'), - url(r'^meetupUser/$', views.meetupUser, name='meetupUser'), - url(r'^yelp/$', views.yelp, name='yelp'), -) + url(r'^', include(router.urls)), + url(r'^register/$', views.register, name='register'), + url(r'^login/$', views.user_login, name='login'), + url(r'^logout/$', views.user_logout, name='logout'), + url(r'^api/$', views.api_examples, name='api'), + url(r'^steam/$', views.steam, name='steam'), + url(r'^steamDiscountedGames/$', views.steamDiscountedGames, name='steamDiscountedGames'), + url(r'^githubResume/$', views.githubResume, name='githubResume'), + url(r'^githubUser/$', views.githubUser, name='githubUser'), + url(r'^githubTopRepositories/$', views.githubTopRepositories, name='githubTopRepositories'), + url(r'^tumblr/$', views.tumblr, name='tumblr'), + url(r'^linkedin/$', views.linkedin, name='linkedin'), + url(r'^twilio/$', views.twilio, name='twilio'), + url(r'^instagram/$', views.instagram, name='instagram'), + url(r'^instagram_login/$', views.instagram_login, name='instagram_login'), + url(r'^instagramUser/$', views.instagramUser, name='instagramUser'), + url(r'^instagramMediaByLocation/$', views.instagramMediaByLocation, + name='instagramMediaByLocation'), # + url(r'^instagramUserMedia/$', views.instagramUserMedia, name='instagramUserMedia'), + url(r'^twitter/$', views.twitter, name='twitter'), + url(r'^twitterTweets/$', views.twitterTweets, name='twitterTweets'), + url(r'^tumblr_login/$', views.tumblr_login, name='tumblr_login'), + url(r'^twitter_login/$', views.twitter_login, name='twitter_login'), + url(r'^github_login/$', views.github_login, name='github_login'), + url(r'^linkedin_login/$', views.linkedin_login, name='linkedin_login'), + url(r'^facebook_login/$', views.facebook_login, name='facebook_login'), + url(r'^facebook/$', views.facebook, name='facebook'), + url(r'^google_login/$', views.google_login, name='google_login'), + url(r'^google/$', views.googlePlus, name='googlePlus'), + url(r'^dropbox_login/$', views.dropbox_login, name='dropbox_login'), + url(r'^dropbox/$', views.dropbox, name='dropbox'), + url(r'^dropboxSearchFile/$', views.dropboxSearchFile, name='dropboxSearchFile'), + url(r'^foursquare_login/$', views.foursquare_login, name='foursquare_login'), + url(r'^foursquare/$', views.foursquare, name='foursquare'), + url(r'^quandlSnp500/$', views.quandlSnp500, name='quandlsnp500'), + url(r'^quandlNasdaq/$', views.quandlNasdaq, name='quandlnasdaq'), + url(r'^quandlNasdaqdiff/$', views.quandlNasdaqdiff, name='quandlnasdaqdiff'), + url(r'^quandlDowJones/$', views.quandlDowJones, name='quandldowjones'), + url(r'^quandlstocks/$', views.quandlstocks, name='quandlstocks'), + url(r'^quandlapple/$', views.quandlapple, name='quandlapple'), + url(r'^quandlapplediff/$', views.quandlapplediff, name='quandlapplediff'), + url(r'^quandlDowJonesdiff/$', views.quandlDowJonesdiff, name='quandldowjonesdiff'), + url(r'^quandlSnp500diff/$', views.quandlSnp500diff, name='quandlsnp500diff'), + url(r'^nytimespop/$', views.nytimespop, name='nytimespop'), + url(r'^nytimestop/$', views.nytimestop, name='nytimestop'), + url(r'^nytimesarticles/$', views.nytimesarticles, name='nytimesarticles'), + url(r'^meetup/$', views.meetup, name='meetup'), + url(r'^meetupToken/$', views.meetupToken, name='meetupToken'), + url(r'^meetupUser/$', views.meetupUser, name='meetupUser'), + url(r'^yelp/$', views.yelp, name='yelp'), + url(r'^upload_file/$', views.upload_file, name='upload_file'), + url(r'^read_csv/?filename=', views.csv_reader, name='csv_reader'), + ) diff --git a/hackathon_starter/hackathon/views.py b/hackathon_starter/hackathon/views.py index 2370b2a..dbdbaa0 100644 --- a/hackathon_starter/hackathon/views.py +++ b/hackathon_starter/hackathon/views.py @@ -1,4 +1,935 @@ # Django +from django.core.files.storage import FileSystemStorage +from django.shortcuts import render +from django.contrib.auth import logout +from django.template import RequestContext, loader +from django.contrib.auth import authenticate, login +from django.http import HttpResponse, HttpResponseRedirect +from django.conf import settings +from django.contrib.auth import authenticate, login, logout +from django.contrib.auth.models import User +from django.contrib.auth.decorators import login_required +from django.views.decorators.csrf import csrf_exempt +from django.http import JsonResponse +from .forms import UploadFileForm +# Django REST Framework +from rest_framework import viewsets, mixins +import csv +import os + +# Scripts +from scripts.steam import gamespulling, steamidpulling +from scripts.github import * +from scripts.tumblr import TumblrOauthClient +from scripts.twilioapi import * +from scripts.instagram import * +from scripts.scraper import steamDiscounts +from scripts.quandl import * +from scripts.twitter import TwitterOauthClient +from scripts.nytimes import * +from scripts.meetup import * +from scripts.linkedin import LinkedinOauthClient +from scripts.yelp import requestData +from scripts.facebook import * +from scripts.googlePlus import * +from scripts.dropbox import * +from scripts.foursquare import * + +# Python +import oauth2 as oauth +import simplejson as json +import requests + +# Models +from hackathon.models import * +from hackathon.serializers import SnippetSerializer +from hackathon.forms import UserForm + +profile_track = None +getTumblr = TumblrOauthClient(settings.TUMBLR_CONSUMER_KEY, settings.TUMBLR_CONSUMER_SECRET) +getInstagram = InstagramOauthClient(settings.INSTAGRAM_CLIENT_ID, settings.INSTAGRAM_CLIENT_SECRET) +getTwitter = TwitterOauthClient(settings.TWITTER_CONSUMER_KEY, settings.TWITTER_CONSUMER_SECRET, + settings.TWITTER_ACCESS_TOKEN, settings.TWITTER_ACCESS_TOKEN_SECRET) +getGithub = GithubOauthClient('2a11ce63ea7952d21f02', '7e20f82a34698fb33fc837186e96b12aaca2618d') +getLinkedIn = LinkedinOauthClient(settings.LINKEDIN_CLIENT_ID, settings.LINKEDIN_CLIENT_SECRET) +getFacebook = FacebookOauthClient(settings.FACEBOOK_APP_ID, settings.FACEBOOK_APP_SECRET) +getGoogle = GooglePlus(settings.GOOGLE_PLUS_APP_ID, settings.GOOGLE_PLUS_APP_SECRET) +getDropbox = DropboxOauthClient(settings.DROPBOX_APP_ID, settings.DROPBOX_APP_SECRET) +getFoursquare = FoursquareOauthClient(settings.FOURSQUARE_APP_ID, settings.FOURSQUARE_APP_SECRET) + + +def index(request): + print "index: " + str(request.user) + + if not request.user.is_active: + if request.GET.items(): + if profile_track == 'github': + code = request.GET['code'] + getGithub.get_access_token(code) + getGithub.getUserInfo() + print getGithub.access_token + try: + user = User.objects.get(username=getGithub.username + '_github') + except User.DoesNotExist: + username = getGithub.username + '_github' + new_user = User.objects.create_user(username, username + '@madewithgithub.com', 'password') + new_user.save() + try: + profile = GithubProfile.objects.get(user=new_user.id) + profile.access_token = getGithub.access_token + except GithubProfile.DoesNotExist: + profile = GithubProfile(user=new_user, access_token=getGithub.access_token, + scopes=getGithub.scopes, github_user=getGithub.username) + profile.save() + user = authenticate(username=getGithub.username + '_github', password='password') + login(request, user) + elif profile_track == 'twitter': + oauth_verifier = request.GET['oauth_verifier'] + getTwitter.get_access_token_url(oauth_verifier) + + try: + user = User.objects.get(username=getTwitter.username + '_twitter') # (username=getTwitter.username) + except User.DoesNotExist: + username = getTwitter.username + '_twitter' + new_user = User.objects.create_user(username, username + '@madewithtwitter.com', 'password') + new_user.save() + profile = TwitterProfile(user=new_user, oauth_token=getTwitter.oauth_token, + oauth_token_secret=getTwitter.oauth_token_secret, + twitter_user=getTwitter.username) + profile.save() + user = authenticate(username=getTwitter.username + '_twitter', password='password') + login(request, user) + elif profile_track == 'instagram': + code = request.GET['code'] + getInstagram.get_access_token(code) + + try: + user = User.objects.get(username=getInstagram.user_data['username'] + '_instagram') + except User.DoesNotExist: + username = getInstagram.user_data['username'] + '_instagram' + new_user = User.objects.create_user(username, username + '@madewithinstagram.com', 'password') + new_user.save() + profile = InstagramProfile(user=new_user, access_token=getInstagram.access_token, + instagram_user=getInstagram.user_data['username']) + profile.save() + user = authenticate(username=getInstagram.user_data['username'] + '_instagram', password='password') + login(request, user) + elif profile_track == 'linkedin': + code = request.GET['code'] + getLinkedIn.get_access_token(code) + getLinkedIn.getUserInfo() + + try: + user = User.objects.get(username=getLinkedIn.user_id + '_linkedin') + except User.DoesNotExist: + username = getLinkedIn.user_id + '_linkedin' + new_user = User.objects.create_user(username, username + '@madwithlinkedin.com', 'password') + new_user.save() + try: + profile = LinkedinProfile.objects.get(user=new_user.id) + profile.access_token = LinkedinProfile.access_token + except LinkedinProfile.DoesNotExist: + profile = LinkedinProfile(user=new_user, access_token=getLinkedIn.access_token, + linkedin_user=getLinkedIn.user_id) + profile.save() + user = authenticate(username=getLinkedIn.user_id + '_linkedin', password='password') + login(request, user) + + elif profile_track == 'facebook': + code = request.GET['code'] + getFacebook.get_access_token(code) + userInfo = getFacebook.get_user_info() + username = userInfo['first_name'] + userInfo['last_name'] + + try: + user = User.objects.get(username=username + '_facebook') + except User.DoesNotExist: + new_user = User.objects.create_user(username + '_facebook', username + '@madewithfacbook', + 'password') + new_user.save() + + try: + profile = FacebookProfile.objects.get(user=new_user.id) + profile.access_token = getFacebook.access_token + except: + profile = FacebookProfile() + profile.user = new_user + profile.fb_user_id = userInfo['id'] + profile.profile_url = userInfo['link'] + profile.access_token = getFacebook.access_token + profile.save() + user = authenticate(username=username + '_facebook', password='password') + login(request, user) + elif profile_track == 'tumblr': + if not getTumblr.is_authorized: + oauth_verifier = request.GET['oauth_verifier'] + getTumblr.access_token_url(oauth_verifier) + getTumblr.getUserInfo() + try: + user = User.objects.get(username=getTumblr.username + '_tumblr') + except User.DoesNotExist: + username = getTumblr.username + '_tumblr' + new_user = User.objects.create_user(username, username + '@madewithtumblr.com', 'password') + new_user.save() + try: + profile = TumblrProfile.objects.get(user=new_user.id) + profile.access_token = getTumblr.access_token['oauth_token'] + profile.access_token_secret = getTumblr.access_token['oauth_token_secret'] + except TumblrProfile.DoesNotExist: + profile = TumblrProfile(user=new_user, access_token=getTumblr.access_token['oauth_token'], + access_token_secret=getTumblr.access_token['oauth_token_secret'], + tumblr_user=getTumblr.username) + profile.save() + user = authenticate(username=getTumblr.username + '_tumblr', password='password') + login(request, user) + + + elif profile_track == 'google': + code = request.GET['code'] + state = request.GET['state'] + getGoogle.get_access_token(code, state) + userInfo = getGoogle.get_user_info() + username = userInfo['given_name'] + userInfo['family_name'] + + try: + user = User.objects.get(username=username + '_google') + except User.DoesNotExist: + new_user = User.objects.create_user(username + '_google', username + '@madewithgoogleplus', + 'password') + new_user.save() + + try: + profle = GoogleProfile.objects.get(user=new_user.id) + profile.access_token = getGoogle.access_token + except: + profile = GoogleProfile() + profile.user = new_user + profile.google_user_id = userInfo['id'] + profile.access_token = getGoogle.access_token + profile.profile_url = userInfo['link'] + profile.save() + user = authenticate(username=username + '_google', password='password') + login(request, user) + + elif profile_track == 'dropbox': + code = request.GET['code'] + state = request.GET['state'] + getDropbox.get_access_token(code, state) + userInfo = getDropbox.get_user_info() + username = userInfo['name_details']['given_name'] + userInfo['name_details']['surname'] + + try: + user = User.objects.get(username=username + '_dropbox') + except User.DoesNotExist: + new_user = User.objects.create_user(username + '_dropbox', username + '@madewithdropbox', + 'password') + new_user.save() + + try: + profile = DropboxProfile.objects.get(user=new_user.id) + profile.access_token = getDropbox.access_token + except: + profile = DropboxProfile() + profile.user = new_user + profile.access_token = getDropbox.access_token + profile.dropbox_user_id = userInfo['uid'] + profile.save() + user = authenticate(username=username + '_dropbox', password='password') + login(request, user) + + elif profile_track == 'foursquare': + code = request.GET['code'] + getFoursquare.get_access_token(code) + userInfo = getFoursquare.get_user_info() + username = userInfo['firstName'] + userInfo['lastName'] + + try: + user = User.objects.get(username=username + '_foursquare') + except User.DoesNotExist: + new_user = User.objects.create_user(username + '_foursquare', username + '@madewithfoursquare', + 'password') + new_user.save() + + try: + profile = FoursquareProfile.object.get(user=new_user.id) + profile.access_token = getFoursquare.access_token + + except: + profile = FoursquareProfile() + profile.user = new_user + profile.foursquare_id = userInfo['id'] + profile.access_token = getFoursquare.access_token + profile.save() + + user = authenticate(username=username + '_foursquare', password='password') + login(request, user) + + + + + + else: + if request.GET.items(): + user = User.objects.get(username=request.user.username) + if profile_track == 'github': + code = request.GET['code'] + getGithub.get_access_token(code) + getGithub.getUserInfo() + + try: + githubUser = GithubProfile.objects.get(user=user.id) + except GithubProfile.DoesNotExist: + profile = GithubProfile(user=new_user, access_token=getGithub.access_token, scopes=getGithub.scopes, + github_user=getGithub.username) + profile.save() + elif profile_track == 'twitter': + oauth_verifier = request.GET['oauth_verifier'] + getTwitter.get_access_token_url(oauth_verifier) + + try: + twitterUser = TwitterProfile.objects.get(user=user.id) + except TwitterProfile.DoesNotExist: + profile = TwitterProfile(user=user, oauth_token=getTwitter.oauth_token, + oauth_token_secret=getTwitter.oauth_token_secret, + twitter_user=getTwitter.username) + profile.save() + elif profile_track == 'instagram': + code = request.GET['code'] + getInstagram.get_access_token(code) + + try: + instagramUser = InstagramProfile.objects.get(user=user.id) + except InstagramProfile.DoesNotExist: + profile = InstagramProfile(user=user, access_token=getInstagram.access_token, + instagram_user=getInstagram.user_data['username']) + profile.save() + elif profile_track == 'linkedin': + code = request.GET['code'] + getLinkedIn.get_access_token(code) + getLinkedIn.getUserInfo() + + try: + linkedinUser = LinkedinProfile.objects.get(user=user.id) + except LinkedinProfile.DoesNotExist: + profile = LinkedinProfile(user=user, access_token=getLinkedIn.access_token, + linkedin_user=getLinkedIn.user_id) + profile.save() + elif profile_track == 'tumblr': + if not getTumblr.is_authorized: + oauth_verifier = request.GET['oauth_verifier'] + getTumblr.access_token_url(oauth_verifier) + getTumblr.getUserInfo() + + try: + tumblrUser = TumblrProfile.objects.get(user=user.id) + except TumblrProfile.DoesNotExist: + profile = TumblrProfile(user=user, access_token=getTumblr.access_token['oauth_token'], + access_token_secret=getTumblr.access_token['oauth_token_secret'], + tumblr_user=getTumblr.username) + profile.save() + + context = {'hello': 'world'} + return render(request, 'hackathon/index.html', context) + + +################## +# API Examples # +################## + +def api_examples(request): + context = {'title': 'API Examples Page'} + return render(request, 'hackathon/api_examples.html', context) + + +################# +# STEAM API # +################# + +def steam(request): + key = '231E98D442E52B87110816C3D5114A1D' + SteamUN = "Marorin" + steamID = steamidpulling(SteamUN, key) + game = gamespulling(steamID, key) + return render(request, 'hackathon/steam.html', {"game": game}) + + +def steamDiscountedGames(request): + data = steamDiscounts() + return JsonResponse({'data': data}) + + +################# +# FACEBOOK API # +################# + +def facebook(request): + ''' + This is an example of getting basic user info and display it + ''' + userInfo = getFacebook.get_user_info() + return render(request, 'hackathon/facebookAPIExample.html', {'userInfo': userInfo}) + + +################# +# GOOGLE API # +################# +def googlePlus(request): + userInfo = getGoogle.get_user_info() + return render(request, 'hackathon/googlePlus.html', {'userInfo': userInfo}) + + +################# +# DROPBOX API # +################# +def dropbox(request): + userInfo = getDropbox.get_user_info() + return render(request, 'hackathon/dropbox.html', {'userInfo': userInfo}) + + +def dropboxSearchFile(request): + if request.method == 'POST': + SEARCH_FILE_URL = 'https://api.dropbox.com/1/search/auto/' + requestParams = {'query': request.POST['filename'], + 'file_limit': '1000', + 'include_deleted': True, + 'access_token': getDropbox.access_token} + response = requests.post(SEARCH_FILE_URL, data=requestParams) + + if response.status_code != 200: + raise (Exception('Invalid response, response code {c}'.format(c=response.status_code))) + + return render(request, 'hackathon/dropboxSearchFile.html', {'data': response.json()}) + + +####################### +# FOURSQUARE API # +####################### + +def foursquare(request): + userInfo = getFoursquare.get_user_info() + return render(request, 'hackathon/foursquare.html', {'data': userInfo}) + + +################# +# YELP API # +################# + +def yelp(request): + data = {} + if request.method == 'POST': + location = request.POST.get('location') + data = requestData(location) + return render(request, 'hackathon/yelp.html', {'data': data}) + + +################# +# MEETUP API # +################# + +def meetup(request): + REDIRECT_URI = 'http://127.0.0.1:8000/hackathon/meetupToken' + AUTHORIZE_URL = 'https://secure.meetup.com/oauth2/authorize?client_id=' + settings.MEETUP_CONSUMER_KEY + '&response_type=code' + '&redirect_uri=' + REDIRECT_URI + return HttpResponseRedirect(AUTHORIZE_URL) + + +def meetupToken(request): + access_token_url = 'https://secure.meetup.com/oauth2/access?' + REDIRECT_URI = 'http://127.0.0.1:8000/hackathon/meetupToken' + url = access_token_url + 'client_id=' + settings.MEETUP_CONSUMER_KEY + '&client_secret=' + settings.MEETUP_CONSUMER_SECRET + '&grant_type=authorization_code' + '&redirect_uri=' + REDIRECT_URI + '&code=' + request.GET.get( + 'code') + + response = requests.post(url) + access_token = json.loads(response.content)['access_token'] + + if not MeetupToken.objects.all().exists(): + meetupToken = MeetupToken(access_token=access_token) + meetupToken.save() + else: + meetupToken = MeetupToken(access_token=access_token) + MeetupToken.objects.all()[0] = meetupToken + return HttpResponseRedirect('http://127.0.0.1:8000/hackathon/meetupUser/') + + +def meetupUser(request): + if not MeetupToken.objects.all().exists(): + return HttpResponseRedirect('http://127.0.0.1:8000/hackathon/meetup') + access_token = MeetupToken.objects.all()[0] + meetupData = {} + userData = retrieveUserData('https://api.meetup.com/2/member/self/?access_token=' + str(access_token)) + meetupData['userData'] = userData + return render(request, 'hackathon/meetup.html', {'data': meetupData}) + + +################# +# QUANDL API # +################# + +def quandlDowJones(request): + '''Returns JSON response about the latest dowjones index.''' + dowjonesdata = fetchData(settings.QUANDLAPIKEY, 'https://www.quandl.com/api/v1/datasets/BCB/UDJIAD1.json?') + print dowjonesdata + return JsonResponse({'data': dowjonesdata}) + + +def quandlSnp500(request): + '''Returns JSON response about the latest SNP 500 index.''' + snpdata = fetchData(settings.QUANDLAPIKEY, 'https://www.quandl.com/api/v1/datasets/YAHOO/INDEX_GSPC.json?') + return JsonResponse({'data': snpdata}) + + +def quandlNasdaq(request): + '''Returns JSON response about the latest nasdaq index.''' + nasdaqdata = fetchData(settings.QUANDLAPIKEY, 'https://www.quandl.com/api/v1/datasets/NASDAQOMX/COMP.json?') + return JsonResponse({'data': nasdaqdata}) + + +def quandlapple(request): + '''Returns JSON response about the latest apple stock.''' + appledata = fetchstockData(settings.QUANDLAPIKEY, 'https://www.quandl.com/api/v1/datasets/GOOG/NASDAQ_AAPL.json') + return JsonResponse({'data': appledata}) + + +def quandlNasdaqdiff(request): + '''Returns JSON response about the latest nasdaq index.''' + nasdaqdata = rdiffData(settings.QUANDLAPIKEY, 'https://www.quandl.com/api/v1/datasets/NASDAQOMX/COMP.json?') + return JsonResponse({'data': nasdaqdata}) + + +def quandlSnp500diff(request): + '''Returns JSON response about the latest SNP 500 index.''' + snpdata = rdiffData(settings.QUANDLAPIKEY, 'https://www.quandl.com/api/v1/datasets/YAHOO/INDEX_GSPC.json?') + return JsonResponse({'data': snpdata}) + + +def quandlDowJonesdiff(request): + '''Returns JSON response about the latest dowjones index.''' + dowjonesdata = rdiffData(settings.QUANDLAPIKEY, 'https://www.quandl.com/api/v1/datasets/BCB/UDJIAD1.json?') + return JsonResponse({'data': dowjonesdata}) + + +def quandlapplediff(request): + '''Returns JSON response about the latest apple stock.''' + appledata = rdiffData(settings.QUANDLAPIKEY, 'https://www.quandl.com/api/v1/datasets/GOOG/NASDAQ_AAPL.json') + return JsonResponse({'data': appledata}) + + +def quandlstocks(request): + everyData = {} + dowjonesdata = fetchData(settings.QUANDLAPIKEY, 'https://www.quandl.com/api/v1/datasets/BCB/UDJIAD1.json?') + everyData['dow'] = dowjonesdata + everyData['dowdiff'] = rdiffData(settings.QUANDLAPIKEY, 'https://www.quandl.com/api/v1/datasets/BCB/UDJIAD1.json?') + snpdata = fetchData(settings.QUANDLAPIKEY, 'https://www.quandl.com/api/v1/datasets/YAHOO/INDEX_GSPC.json?') + everyData['snp'] = snpdata + everyData['snpdiff'] = rdiffData(settings.QUANDLAPIKEY, + 'https://www.quandl.com/api/v1/datasets/YAHOO/INDEX_GSPC.json?') + nasdaqdata = fetchData(settings.QUANDLAPIKEY, 'https://www.quandl.com/api/v1/datasets/NASDAQOMX/COMP.json?') + everyData['nasdaq'] = nasdaqdata + everyData['nasdaqdiff'] = rdiffData(settings.QUANDLAPIKEY, + 'https://www.quandl.com/api/v1/datasets/NASDAQOMX/COMP.json?') + everyData['apple'] = fetchstockData(settings.QUANDLAPIKEY, + 'https://www.quandl.com/api/v1/datasets/GOOG/NASDAQ_AAPL.json') + everyData['applediff'] = rdiffData(settings.QUANDLAPIKEY, + 'https://www.quandl.com/api/v1/datasets/GOOG/NASDAQ_AAPL.json') + return render(request, 'hackathon/quandl.html', {'everyData': everyData}) + + +################# +# NYTIMES API # +################# + +def nytimespop(request): + '''Returns JSON response about the most viewed articles for the last 24 hours.''' + popdata = fetcharticle(settings.POPAPIKEY, + 'http://api.nytimes.com/svc/mostpopular/v2/mostviewed/all-sections/1.json?') + return JSONResponse({'data': popdata}) + + +def nytimestop(request): + '''Returns JSON response about the articles located in the homepage''' + topdata = fetcharticle(settings.TOPAPIKEY, 'http://api.nytimes.com/svc/topstories/v1/home.json?') + return JSONResponse({'data': topdata}) + + +def nytimesarticles(request): + everyData = {} + popdata = fetcharticle(settings.POPAPIKEY, + 'http://api.nytimes.com/svc/mostpopular/v2/mostviewed/all-sections/1.json?') + topdata = topdata = fetcharticle(settings.TOPAPIKEY, 'http://api.nytimes.com/svc/topstories/v1/home.json?') + everyData['top'] = topdata + everyData['pop'] = popdata + return render(request, 'hackathon/nytimes.html', {'everyData': everyData}) + + +################# +# GITHUB API # +################# + +def githubUser(request): + '''Returns Github Profile data for a specific user.''' + parsedData = {} + if request.method == 'POST': + user = request.POST.get('user') + parsedData['userData'] = getUserData(user, settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET) + return render(request, 'hackathon/github.html', {'data': parsedData}) + + +def githubTopRepositories(request): + '''Returns Top Commited Repositories for a specific Github User''' + + parsedData = {} + if request.method == 'POST': + user = request.POST.get('user') + repositories = getUserRepositories(user, settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET) + list = getTopContributedRepositories(user, repositories, settings.GITHUB_CLIENT_ID, + settings.GITHUB_CLIENT_SECRET) + filtered = filterCommits(list) + parsedData['committed'] = filtered + print parsedData + return render(request, 'hackathon/githubTopRepositories.html', {'data': parsedData}) + + +def githubResume(request): + '''A sample application which pulls various Github data to form a Resume of sorts''' + + allData = {} + userData = getUserData('DrkSephy', settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET) + repositories = getUserRepositories('DrkSephy', settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET) + list = getTopContributedRepositories('DrkSephy', repositories, settings.GITHUB_CLIENT_ID, + settings.GITHUB_CLIENT_SECRET) + filtered = filterCommits(list) + stargazers = getStarGazerCount('DrkSephy', settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET) + filteredStargazers = filterStarGazerCount(stargazers) + forkedRepos = getForkedRepositories('DrkSephy', settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET) + allData['userData'] = userData + allData['filteredData'] = filtered + allData['filteredStargazers'] = filteredStargazers + allData['forkedRepos'] = forkedRepos + return render(request, 'hackathon/githubResume.html', {'data': allData}) + + +################# +# TUMBLR API # +################# + +def tumblr(request): + ''' Tumblr api calls ''' + if getTumblr.is_authorized: + # get blogger twitterthecomic's blog information + blog = getTumblr.getBlogInfo('twitterthecomic') + # get tags that was tagged along starbucks + tagged_blog = getTumblr.getTaggedInfo("starbucks") + # get blog information tagged with starbucks + blogontag = getTumblr.getTaggedBlog("starbucks") + else: + blog, tagged_blog, blogontag = '', '', '' + global profile_track + profile_track = 'tumblr' + tumblr_url = getTumblr.authorize_url() + return HttpResponseRedirect(tumblr_url) + + context = {'title': "What's up Starbucks?", 'blogData': blog, 'blogTag': tagged_blog, 'blogontag': blogontag} + return render(request, 'hackathon/tumblr.html', context) + + +#################### +# INSTAGRAM API # +#################### + +def instagram(request): + print getInstagram.is_authorized + + if getInstagram.is_authorized: + if request.method == 'GET': + if request.GET.items(): + instagram_tag = request.GET.get('instagram_tag') + instagramUser = InstagramProfile.objects.get(user=request.user) + tagged_media = getTaggedMedia(instagram_tag, instagramUser.access_token) + else: + instagram_tag, tagged_media = '', '' + else: + global profile_track + profile_track = 'instagram' + instagram_url = getInstagram.get_authorize_url() + return HttpResponseRedirect(instagram_url) + + context = {'title': 'Instagram', 'tagged_media': tagged_media, 'search_tag': instagram_tag} + return render(request, 'hackathon/instagram.html', context) + + +def instagramUser(request): + ''' Returns JSON response about a specific Instagram User. ''' + + access_token = InstagramProfile.objects.get(instagram_user='mk200789').access_token + parsedData = getUserInfo(access_token) + return JsonResponse({'data': parsedData}) + + +def instagramUserMedia(request): + ''' Returns JSON response about a specific Instagram User's Media. ''' + + access_token = InstagramProfile.objects.get(instagram_user='mk200789').access_token + parsedData = getUserMedia(32833691, access_token) + return JsonResponse({'data': parsedData}) + + +def instagramMediaByLocation(request): + print request.user + if request.method == 'GET': + if request.GET.items(): + # check if user has a User profile + if request.user in User.objects.all(): + # check if user has an Instagram profile + user = User.objects.get(username=request.user) + # if user has an Instagram profile, query the search + if InstagramProfile.objects.all().filter(user=user.id): + address = request.GET.get('address_field') + access_token = InstagramProfile.objects.get(user=user.id).access_token + geocode_result = searchForLocation(address) + if geocode_result: + location_ids = searchLocationIds(geocode_result['lat'], geocode_result['lng'], access_token) + media = searchLocationMedia(location_ids, access_token) + title = address + err_msg = '' + else: + title, media, err_msg, location_ids, geocode_result = 'Media by location', '', str( + request.user) + ' does not have an InstagramProfile', '', '' + else: + title, media, err_msg, location_ids, geocode_result = 'Media by location', '', '', '', '' + + context = {'title': title, 'geocode_result': geocode_result, 'media': media, 'list_id': location_ids, + 'err_msg': err_msg} + return render(request, 'hackathon/instagram_q.html', context) + + +#################### +# TWITTER API # +#################### + +def twitter(request): + if getTwitter.is_authorized: + value = getTwitter.get_trends_available(settings.YAHOO_CONSUMER_KEY) + else: + global profile_track + profile_track = 'twitter' + twitter_url = getTwitter.get_authorize_url() + return HttpResponseRedirect(twitter_url) + + context = {'title': 'twitter', 'value': value} + return render(request, 'hackathon/twitter.html', context) + + +def twitterTweets(request): + print getTwitter.is_authorized + if getTwitter.is_authorized: + if request.method == 'GET': + if request.GET.items(): + tweets = request.GET.get('tweets') + content, jsonlist = getTwitter.get_tweets(tweets) + else: + content, jsonlist = '', '' + else: + global profile_track + profile_track = 'twitter' + twitter_url = getTwitter.get_authorize_url() + return HttpResponseRedirect(twitter_url) + + context = {'title': 'twitter tweet', 'content': content, 'data': jsonlist} + return render(request, 'hackathon/twitter_tweet.html', context) + + +################## +# LINKEDIN API # +################## + +def linkedin(request): + if getLinkedIn.is_authorized: + content = getLinkedIn.getUserInfo() + else: + global profile_track + profile_track = 'linkedin' + linkedin_url = getLinkedIn.get_authorize_url() + return HttpResponseRedirect(linkedin_url) + + context = {'title': 'linkedin example', 'content': content} + return render(request, 'hackathon/linkedin.html', context) + + +######################### +# Snippet RESTful Model # +######################### + +class CRUDBaseView(mixins.ListModelMixin, + mixins.CreateModelMixin, + mixins.RetrieveModelMixin, + mixins.UpdateModelMixin, + mixins.DestroyModelMixin, + viewsets.GenericViewSet): + pass + + +class SnippetView(CRUDBaseView): + serializer_class = SnippetSerializer + queryset = Snippet.objects.all() + + +################## +# Twilio API # +################## + +def twilio(request): + if request.method == 'POST': + number = request.POST.get('number') + message = request.POST.get('message') + sendSMS(str(message), str(number), '+13473781813') + context = {'message': 'Your message has been sent successfully!'} + return HttpResponseRedirect('/hackathon/api/') + return render(request, 'hackathon/twilio.html') + + +###################### +# Registration Views # +###################### + +def register(request): + registered = False + if request.method == 'POST': + user_form = UserForm(data=request.POST) + if user_form.is_valid(): + user = user_form.save() + user.set_password(user.password) + user.save() + registered = True + return HttpResponseRedirect('/hackathon/login/') + else: + print user_form.errors + else: + user_form = UserForm() + + return render(request, + 'hackathon/register.html', + {'user_form': user_form, 'registered': registered}) + + +def user_login(request): + if request.method == 'POST': + username = request.POST.get('username') + password = request.POST.get('password') + + user = authenticate(username=username, password=password) + + if user: + if user.is_active: + login(request, user) + return HttpResponseRedirect('/hackathon/api/') + else: + return HttpResponse("Your Django Hackathon account is disabled.") + else: + print "Invalid login details: {0}, {1}".format(username, password) + return HttpResponse("Invalid login details supplied.") + + else: + return render(request, 'hackathon/login.html', {}) + + +def user_logout(request): + logout(request) + return HttpResponseRedirect('/hackathon/login/') + + +def instagram_login(request): + global profile_track + profile_track = 'instagram' + instagram_url = getInstagram.get_authorize_url() + return HttpResponseRedirect(instagram_url) + + +def tumblr_login(request): + global profile_track + profile_track = 'tumblr' + tumblr_url = getTumblr.authorize_url() + return HttpResponseRedirect(tumblr_url) + + +def twitter_login(request): + global profile_track + profile_track = 'twitter' + twitter_url = getTwitter.get_authorize_url() + return HttpResponseRedirect(twitter_url) + + +def github_login(request): + global profile_track + profile_track = 'github' + github_url = getGithub.get_authorize_url() + return HttpResponseRedirect(github_url) + + +def linkedin_login(request): + global profile_track + profile_track = 'linkedin' + linkedin_url = getLinkedIn.get_authorize_url() + return HttpResponseRedirect(linkedin_url) + + +def facebook_login(request): + global profile_track + profile_track = 'facebook' + facebook_url = getFacebook.get_authorize_url() + return HttpResponseRedirect(facebook_url) + + +def google_login(request): + global profile_track + profile_track = 'google' + google_url = getGoogle.get_authorize_url() + return HttpResponseRedirect(google_url) + + +def dropbox_login(request): + global profile_track + profile_track = 'dropbox' + dropbox_url = getDropbox.get_authorize_url() + return HttpResponseRedirect(dropbox_url) + + +def foursquare_login(request): + global profile_track + profile_track = 'foursquare' + forsquare_url = getFoursquare.get_authorize_url() + return HttpResponseRedirect(forsquare_url) + + +def upload_file(request): + if request.method == 'POST' and request.FILES['filename']: + myfile = request.FILES['filename'] + fs = FileSystemStorage() + filename = fs.save(myfile.name, myfile) + uploaded_file_url = fs.url(filename) + return render(request, 'hackathon/upload_csv.html', { + 'uploaded_file_url': uploaded_file_url + }) + return render(request, 'hackathon/upload_csv.html') + + +def csv_reader(request): + if request.method == 'POST': + filename = request.FILES['filename'].name + with open(filename, 'r') as csvfile: + line_reader = csv.reader(csvfile) + categories = next(line_reader) + a = [] + for row in line_reader: + b = row + c = {} + for i in range(len(b)): + c[categories[i]] = b[i] + a.append(c) + csvfile.close() + return render(request, 'hackathon/view_csv_requests.html', {'requests': a}) + return render(request, 'hackathon/upload_csv.html') # Django + + +from django.core.files.storage import FileSystemStorage from django.shortcuts import render from django.contrib.auth import logout from django.template import RequestContext, loader @@ -13,6 +944,7 @@ # Django REST Framework from rest_framework import viewsets, mixins +import csv # Scripts from scripts.steam import gamespulling, steamidpulling @@ -42,11 +974,11 @@ from hackathon.serializers import SnippetSerializer from hackathon.forms import UserForm - profile_track = None getTumblr = TumblrOauthClient(settings.TUMBLR_CONSUMER_KEY, settings.TUMBLR_CONSUMER_SECRET) getInstagram = InstagramOauthClient(settings.INSTAGRAM_CLIENT_ID, settings.INSTAGRAM_CLIENT_SECRET) -getTwitter = TwitterOauthClient(settings.TWITTER_CONSUMER_KEY, settings.TWITTER_CONSUMER_SECRET, settings.TWITTER_ACCESS_TOKEN, settings.TWITTER_ACCESS_TOKEN_SECRET) +getTwitter = TwitterOauthClient(settings.TWITTER_CONSUMER_KEY, settings.TWITTER_CONSUMER_SECRET, + settings.TWITTER_ACCESS_TOKEN, settings.TWITTER_ACCESS_TOKEN_SECRET) getGithub = GithubOauthClient('2a11ce63ea7952d21f02', '7e20f82a34698fb33fc837186e96b12aaca2618d') getLinkedIn = LinkedinOauthClient(settings.LINKEDIN_CLIENT_ID, settings.LINKEDIN_CLIENT_SECRET) getFacebook = FacebookOauthClient(settings.FACEBOOK_APP_ID, settings.FACEBOOK_APP_SECRET) @@ -54,6 +986,7 @@ getDropbox = DropboxOauthClient(settings.DROPBOX_APP_ID, settings.DROPBOX_APP_SECRET) getFoursquare = FoursquareOauthClient(settings.FOURSQUARE_APP_ID, settings.FOURSQUARE_APP_SECRET) + def index(request): print "index: " + str(request.user) @@ -65,46 +998,50 @@ def index(request): getGithub.getUserInfo() print getGithub.access_token try: - user = User.objects.get(username = getGithub.username + '_github') + user = User.objects.get(username=getGithub.username + '_github') except User.DoesNotExist: username = getGithub.username + '_github' - new_user = User.objects.create_user(username, username+'@madewithgithub.com', 'password') + new_user = User.objects.create_user(username, username + '@madewithgithub.com', 'password') new_user.save() try: - profile = GithubProfile.objects.get(user = new_user.id) + profile = GithubProfile.objects.get(user=new_user.id) profile.access_token = getGithub.access_token except GithubProfile.DoesNotExist: - profile = GithubProfile(user=new_user, access_token=getGithub.access_token, scopes=getGithub.scopes ,github_user=getGithub.username) + profile = GithubProfile(user=new_user, access_token=getGithub.access_token, + scopes=getGithub.scopes, github_user=getGithub.username) profile.save() - user = authenticate(username=getGithub.username+'_github', password='password') + user = authenticate(username=getGithub.username + '_github', password='password') login(request, user) elif profile_track == 'twitter': oauth_verifier = request.GET['oauth_verifier'] getTwitter.get_access_token_url(oauth_verifier) try: - user = User.objects.get(username = getTwitter.username + '_twitter')#(username=getTwitter.username) + user = User.objects.get(username=getTwitter.username + '_twitter') # (username=getTwitter.username) except User.DoesNotExist: username = getTwitter.username + '_twitter' - new_user = User.objects.create_user(username, username+'@madewithtwitter.com', 'password') + new_user = User.objects.create_user(username, username + '@madewithtwitter.com', 'password') new_user.save() - profile = TwitterProfile(user = new_user,oauth_token = getTwitter.oauth_token, oauth_token_secret= getTwitter.oauth_token_secret, twitter_user=getTwitter.username) + profile = TwitterProfile(user=new_user, oauth_token=getTwitter.oauth_token, + oauth_token_secret=getTwitter.oauth_token_secret, + twitter_user=getTwitter.username) profile.save() - user = authenticate(username=getTwitter.username+'_twitter', password='password') + user = authenticate(username=getTwitter.username + '_twitter', password='password') login(request, user) elif profile_track == 'instagram': code = request.GET['code'] getInstagram.get_access_token(code) try: - user = User.objects.get(username=getInstagram.user_data['username']+'_instagram') + user = User.objects.get(username=getInstagram.user_data['username'] + '_instagram') except User.DoesNotExist: - username = getInstagram.user_data['username']+'_instagram' - new_user = User.objects.create_user(username, username+'@madewithinstagram.com', 'password') + username = getInstagram.user_data['username'] + '_instagram' + new_user = User.objects.create_user(username, username + '@madewithinstagram.com', 'password') new_user.save() - profile = InstagramProfile(user = new_user, access_token = getInstagram.access_token, instagram_user=getInstagram.user_data['username']) + profile = InstagramProfile(user=new_user, access_token=getInstagram.access_token, + instagram_user=getInstagram.user_data['username']) profile.save() - user = authenticate(username=getInstagram.user_data['username']+'_instagram' , password='password') + user = authenticate(username=getInstagram.user_data['username'] + '_instagram', password='password') login(request, user) elif profile_track == 'linkedin': code = request.GET['code'] @@ -112,18 +1049,19 @@ def index(request): getLinkedIn.getUserInfo() try: - user = User.objects.get(username=getLinkedIn.user_id+'_linkedin') + user = User.objects.get(username=getLinkedIn.user_id + '_linkedin') except User.DoesNotExist: - username = getLinkedIn.user_id+'_linkedin' - new_user = User.objects.create_user(username, username+'@madwithlinkedin.com', 'password') + username = getLinkedIn.user_id + '_linkedin' + new_user = User.objects.create_user(username, username + '@madwithlinkedin.com', 'password') new_user.save() try: - profile =LinkedinProfile.objects.get(user = new_user.id) + profile = LinkedinProfile.objects.get(user=new_user.id) profile.access_token = LinkedinProfile.access_token except LinkedinProfile.DoesNotExist: - profile = LinkedinProfile(user=new_user, access_token=getLinkedIn.access_token, linkedin_user=getLinkedIn.user_id) + profile = LinkedinProfile(user=new_user, access_token=getLinkedIn.access_token, + linkedin_user=getLinkedIn.user_id) profile.save() - user = authenticate(username=getLinkedIn.user_id+'_linkedin', password='password') + user = authenticate(username=getLinkedIn.user_id + '_linkedin', password='password') login(request, user) elif profile_track == 'facebook': @@ -133,9 +1071,10 @@ def index(request): username = userInfo['first_name'] + userInfo['last_name'] try: - user = User.objects.get(username=username+'_facebook') + user = User.objects.get(username=username + '_facebook') except User.DoesNotExist: - new_user = User.objects.create_user(username+'_facebook', username+'@madewithfacbook', 'password') + new_user = User.objects.create_user(username + '_facebook', username + '@madewithfacbook', + 'password') new_user.save() try: @@ -148,7 +1087,7 @@ def index(request): profile.profile_url = userInfo['link'] profile.access_token = getFacebook.access_token profile.save() - user = authenticate(username=username+'_facebook', password='password') + user = authenticate(username=username + '_facebook', password='password') login(request, user) elif profile_track == 'tumblr': if not getTumblr.is_authorized: @@ -156,19 +1095,21 @@ def index(request): getTumblr.access_token_url(oauth_verifier) getTumblr.getUserInfo() try: - user = User.objects.get(username = getTumblr.username + '_tumblr') + user = User.objects.get(username=getTumblr.username + '_tumblr') except User.DoesNotExist: username = getTumblr.username + '_tumblr' - new_user = User.objects.create_user(username, username+'@madewithtumblr.com', 'password') + new_user = User.objects.create_user(username, username + '@madewithtumblr.com', 'password') new_user.save() try: - profile =TumblrProfile.objects.get(user = new_user.id) + profile = TumblrProfile.objects.get(user=new_user.id) profile.access_token = getTumblr.access_token['oauth_token'] profile.access_token_secret = getTumblr.access_token['oauth_token_secret'] except TumblrProfile.DoesNotExist: - profile = TumblrProfile(user=new_user, access_token=getTumblr.access_token['oauth_token'], access_token_secret= getTumblr.access_token['oauth_token_secret'], tumblr_user=getTumblr.username) + profile = TumblrProfile(user=new_user, access_token=getTumblr.access_token['oauth_token'], + access_token_secret=getTumblr.access_token['oauth_token_secret'], + tumblr_user=getTumblr.username) profile.save() - user = authenticate(username=getTumblr.username+'_tumblr', password='password') + user = authenticate(username=getTumblr.username + '_tumblr', password='password') login(request, user) @@ -180,13 +1121,14 @@ def index(request): username = userInfo['given_name'] + userInfo['family_name'] try: - user = User.objects.get(username=username+'_google') + user = User.objects.get(username=username + '_google') except User.DoesNotExist: - new_user = User.objects.create_user(username+'_google', username+'@madewithgoogleplus', 'password') + new_user = User.objects.create_user(username + '_google', username + '@madewithgoogleplus', + 'password') new_user.save() try: - profle = GoogleProfile.objects.get(user = new_user.id) + profle = GoogleProfile.objects.get(user=new_user.id) profile.access_token = getGoogle.access_token except: profile = GoogleProfile() @@ -195,7 +1137,7 @@ def index(request): profile.access_token = getGoogle.access_token profile.profile_url = userInfo['link'] profile.save() - user = authenticate(username=username+'_google', password='password') + user = authenticate(username=username + '_google', password='password') login(request, user) elif profile_track == 'dropbox': @@ -206,9 +1148,10 @@ def index(request): username = userInfo['name_details']['given_name'] + userInfo['name_details']['surname'] try: - user = User.objects.get(username=username+'_dropbox') + user = User.objects.get(username=username + '_dropbox') except User.DoesNotExist: - new_user = User.objects.create_user(username+'_dropbox', username+'@madewithdropbox', 'password') + new_user = User.objects.create_user(username + '_dropbox', username + '@madewithdropbox', + 'password') new_user.save() try: @@ -220,7 +1163,7 @@ def index(request): profile.access_token = getDropbox.access_token profile.dropbox_user_id = userInfo['uid'] profile.save() - user = authenticate(username=username+'_dropbox', password='password') + user = authenticate(username=username + '_dropbox', password='password') login(request, user) elif profile_track == 'foursquare': @@ -230,9 +1173,10 @@ def index(request): username = userInfo['firstName'] + userInfo['lastName'] try: - user = User.objects.get(username=username+'_foursquare') + user = User.objects.get(username=username + '_foursquare') except User.DoesNotExist: - new_user = User.objects.create_user(username+'_foursquare', username+'@madewithfoursquare', 'password') + new_user = User.objects.create_user(username + '_foursquare', username + '@madewithfoursquare', + 'password') new_user.save() try: @@ -246,7 +1190,7 @@ def index(request): profile.access_token = getFoursquare.access_token profile.save() - user = authenticate(username=username+'_foursquare', password='password') + user = authenticate(username=username + '_foursquare', password='password') login(request, user) @@ -255,7 +1199,7 @@ def index(request): else: if request.GET.items(): - user = User.objects.get(username = request.user.username) + user = User.objects.get(username=request.user.username) if profile_track == 'github': code = request.GET['code'] getGithub.get_access_token(code) @@ -264,25 +1208,29 @@ def index(request): try: githubUser = GithubProfile.objects.get(user=user.id) except GithubProfile.DoesNotExist: - profile = GithubProfile(user=new_user, access_token=getGithub.access_token, scopes=getGithub.scopes ,github_user=getGithub.username) + profile = GithubProfile(user=new_user, access_token=getGithub.access_token, scopes=getGithub.scopes, + github_user=getGithub.username) profile.save() elif profile_track == 'twitter': oauth_verifier = request.GET['oauth_verifier'] getTwitter.get_access_token_url(oauth_verifier) try: - twitterUser = TwitterProfile.objects.get(user = user.id) + twitterUser = TwitterProfile.objects.get(user=user.id) except TwitterProfile.DoesNotExist: - profile = TwitterProfile(user = user, oauth_token = getTwitter.oauth_token, oauth_token_secret= getTwitter.oauth_token_secret, twitter_user=getTwitter.username) + profile = TwitterProfile(user=user, oauth_token=getTwitter.oauth_token, + oauth_token_secret=getTwitter.oauth_token_secret, + twitter_user=getTwitter.username) profile.save() elif profile_track == 'instagram': code = request.GET['code'] getInstagram.get_access_token(code) try: - instagramUser = InstagramProfile.objects.get(user= user.id) + instagramUser = InstagramProfile.objects.get(user=user.id) except InstagramProfile.DoesNotExist: - profile = InstagramProfile(user = user, access_token = getInstagram.access_token, instagram_user=getInstagram.user_data['username']) + profile = InstagramProfile(user=user, access_token=getInstagram.access_token, + instagram_user=getInstagram.user_data['username']) profile.save() elif profile_track == 'linkedin': code = request.GET['code'] @@ -292,7 +1240,8 @@ def index(request): try: linkedinUser = LinkedinProfile.objects.get(user=user.id) except LinkedinProfile.DoesNotExist: - profile = LinkedinProfile(user = user, access_token = getLinkedIn.access_token, linkedin_user=getLinkedIn.user_id) + profile = LinkedinProfile(user=user, access_token=getLinkedIn.access_token, + linkedin_user=getLinkedIn.user_id) profile.save() elif profile_track == 'tumblr': if not getTumblr.is_authorized: @@ -303,10 +1252,11 @@ def index(request): try: tumblrUser = TumblrProfile.objects.get(user=user.id) except TumblrProfile.DoesNotExist: - profile = TumblrProfile(user=user, access_token=getTumblr.access_token['oauth_token'], access_token_secret= getTumblr.access_token['oauth_token_secret'], tumblr_user=getTumblr.username) + profile = TumblrProfile(user=user, access_token=getTumblr.access_token['oauth_token'], + access_token_secret=getTumblr.access_token['oauth_token_secret'], + tumblr_user=getTumblr.username) profile.save() - context = {'hello': 'world'} return render(request, 'hackathon/index.html', context) @@ -319,6 +1269,7 @@ def api_examples(request): context = {'title': 'API Examples Page'} return render(request, 'hackathon/api_examples.html', context) + ################# # STEAM API # ################# @@ -328,11 +1279,13 @@ def steam(request): SteamUN = "Marorin" steamID = steamidpulling(SteamUN, key) game = gamespulling(steamID, key) - return render(request,'hackathon/steam.html', {"game": game }) + return render(request, 'hackathon/steam.html', {"game": game}) + def steamDiscountedGames(request): data = steamDiscounts() - return JsonResponse({ 'data': data }) + return JsonResponse({'data': data}) + ################# # FACEBOOK API # @@ -343,22 +1296,24 @@ def facebook(request): This is an example of getting basic user info and display it ''' userInfo = getFacebook.get_user_info() - return render(request, 'hackathon/facebookAPIExample.html', { 'userInfo' : userInfo}) + return render(request, 'hackathon/facebookAPIExample.html', {'userInfo': userInfo}) + ################# # GOOGLE API # ################# def googlePlus(request): - userInfo = getGoogle.get_user_info() - return render(request, 'hackathon/googlePlus.html', {'userInfo' : userInfo}) + return render(request, 'hackathon/googlePlus.html', {'userInfo': userInfo}) + ################# # DROPBOX API # ################# def dropbox(request): userInfo = getDropbox.get_user_info() - return render(request, 'hackathon/dropbox.html', {'userInfo' : userInfo}) + return render(request, 'hackathon/dropbox.html', {'userInfo': userInfo}) + def dropboxSearchFile(request): if request.method == 'POST': @@ -369,18 +1324,19 @@ def dropboxSearchFile(request): 'access_token': getDropbox.access_token} response = requests.post(SEARCH_FILE_URL, data=requestParams) - if response.status_code!=200: - raise(Exception('Invalid response, response code {c}'.format(c=response.status_code))) + if response.status_code != 200: + raise (Exception('Invalid response, response code {c}'.format(c=response.status_code))) return render(request, 'hackathon/dropboxSearchFile.html', {'data': response.json()}) + ####################### # FOURSQUARE API # ####################### def foursquare(request): userInfo = getFoursquare.get_user_info() - return render(request, 'hackathon/foursquare.html', {'data' : userInfo}) + return render(request, 'hackathon/foursquare.html', {'data': userInfo}) ################# @@ -392,7 +1348,8 @@ def yelp(request): if request.method == 'POST': location = request.POST.get('location') data = requestData(location) - return render(request, 'hackathon/yelp.html', { 'data': data }) + return render(request, 'hackathon/yelp.html', {'data': data}) + ################# # MEETUP API # @@ -403,22 +1360,25 @@ def meetup(request): AUTHORIZE_URL = 'https://secure.meetup.com/oauth2/authorize?client_id=' + settings.MEETUP_CONSUMER_KEY + '&response_type=code' + '&redirect_uri=' + REDIRECT_URI return HttpResponseRedirect(AUTHORIZE_URL) + def meetupToken(request): access_token_url = 'https://secure.meetup.com/oauth2/access?' REDIRECT_URI = 'http://127.0.0.1:8000/hackathon/meetupToken' - url = access_token_url + 'client_id=' + settings.MEETUP_CONSUMER_KEY + '&client_secret=' + settings.MEETUP_CONSUMER_SECRET + '&grant_type=authorization_code' + '&redirect_uri=' + REDIRECT_URI + '&code=' + request.GET.get('code') + url = access_token_url + 'client_id=' + settings.MEETUP_CONSUMER_KEY + '&client_secret=' + settings.MEETUP_CONSUMER_SECRET + '&grant_type=authorization_code' + '&redirect_uri=' + REDIRECT_URI + '&code=' + request.GET.get( + 'code') response = requests.post(url) access_token = json.loads(response.content)['access_token'] - + if not MeetupToken.objects.all().exists(): - meetupToken = MeetupToken(access_token = access_token) + meetupToken = MeetupToken(access_token=access_token) meetupToken.save() else: - meetupToken = MeetupToken(access_token = access_token) + meetupToken = MeetupToken(access_token=access_token) MeetupToken.objects.all()[0] = meetupToken return HttpResponseRedirect('http://127.0.0.1:8000/hackathon/meetupUser/') + def meetupUser(request): if not MeetupToken.objects.all().exists(): return HttpResponseRedirect('http://127.0.0.1:8000/hackathon/meetup') @@ -426,7 +1386,8 @@ def meetupUser(request): meetupData = {} userData = retrieveUserData('https://api.meetup.com/2/member/self/?access_token=' + str(access_token)) meetupData['userData'] = userData - return render(request, 'hackathon/meetup.html', { 'data': meetupData }) + return render(request, 'hackathon/meetup.html', {'data': meetupData}) + ################# # QUANDL API # @@ -438,41 +1399,49 @@ def quandlDowJones(request): print dowjonesdata return JsonResponse({'data': dowjonesdata}) + def quandlSnp500(request): '''Returns JSON response about the latest SNP 500 index.''' snpdata = fetchData(settings.QUANDLAPIKEY, 'https://www.quandl.com/api/v1/datasets/YAHOO/INDEX_GSPC.json?') return JsonResponse({'data': snpdata}) + def quandlNasdaq(request): '''Returns JSON response about the latest nasdaq index.''' nasdaqdata = fetchData(settings.QUANDLAPIKEY, 'https://www.quandl.com/api/v1/datasets/NASDAQOMX/COMP.json?') return JsonResponse({'data': nasdaqdata}) + def quandlapple(request): '''Returns JSON response about the latest apple stock.''' appledata = fetchstockData(settings.QUANDLAPIKEY, 'https://www.quandl.com/api/v1/datasets/GOOG/NASDAQ_AAPL.json') return JsonResponse({'data': appledata}) + def quandlNasdaqdiff(request): '''Returns JSON response about the latest nasdaq index.''' nasdaqdata = rdiffData(settings.QUANDLAPIKEY, 'https://www.quandl.com/api/v1/datasets/NASDAQOMX/COMP.json?') return JsonResponse({'data': nasdaqdata}) + def quandlSnp500diff(request): '''Returns JSON response about the latest SNP 500 index.''' snpdata = rdiffData(settings.QUANDLAPIKEY, 'https://www.quandl.com/api/v1/datasets/YAHOO/INDEX_GSPC.json?') return JsonResponse({'data': snpdata}) + def quandlDowJonesdiff(request): '''Returns JSON response about the latest dowjones index.''' dowjonesdata = rdiffData(settings.QUANDLAPIKEY, 'https://www.quandl.com/api/v1/datasets/BCB/UDJIAD1.json?') return JsonResponse({'data': dowjonesdata}) + def quandlapplediff(request): '''Returns JSON response about the latest apple stock.''' appledata = rdiffData(settings.QUANDLAPIKEY, 'https://www.quandl.com/api/v1/datasets/GOOG/NASDAQ_AAPL.json') return JsonResponse({'data': appledata}) + def quandlstocks(request): everyData = {} dowjonesdata = fetchData(settings.QUANDLAPIKEY, 'https://www.quandl.com/api/v1/datasets/BCB/UDJIAD1.json?') @@ -480,13 +1449,18 @@ def quandlstocks(request): everyData['dowdiff'] = rdiffData(settings.QUANDLAPIKEY, 'https://www.quandl.com/api/v1/datasets/BCB/UDJIAD1.json?') snpdata = fetchData(settings.QUANDLAPIKEY, 'https://www.quandl.com/api/v1/datasets/YAHOO/INDEX_GSPC.json?') everyData['snp'] = snpdata - everyData['snpdiff'] = rdiffData(settings.QUANDLAPIKEY, 'https://www.quandl.com/api/v1/datasets/YAHOO/INDEX_GSPC.json?') + everyData['snpdiff'] = rdiffData(settings.QUANDLAPIKEY, + 'https://www.quandl.com/api/v1/datasets/YAHOO/INDEX_GSPC.json?') nasdaqdata = fetchData(settings.QUANDLAPIKEY, 'https://www.quandl.com/api/v1/datasets/NASDAQOMX/COMP.json?') everyData['nasdaq'] = nasdaqdata - everyData['nasdaqdiff'] = rdiffData(settings.QUANDLAPIKEY, 'https://www.quandl.com/api/v1/datasets/NASDAQOMX/COMP.json?') - everyData['apple'] = fetchstockData(settings.QUANDLAPIKEY, 'https://www.quandl.com/api/v1/datasets/GOOG/NASDAQ_AAPL.json') - everyData['applediff'] = rdiffData(settings.QUANDLAPIKEY, 'https://www.quandl.com/api/v1/datasets/GOOG/NASDAQ_AAPL.json') - return render(request, 'hackathon/quandl.html', { 'everyData': everyData }) + everyData['nasdaqdiff'] = rdiffData(settings.QUANDLAPIKEY, + 'https://www.quandl.com/api/v1/datasets/NASDAQOMX/COMP.json?') + everyData['apple'] = fetchstockData(settings.QUANDLAPIKEY, + 'https://www.quandl.com/api/v1/datasets/GOOG/NASDAQ_AAPL.json') + everyData['applediff'] = rdiffData(settings.QUANDLAPIKEY, + 'https://www.quandl.com/api/v1/datasets/GOOG/NASDAQ_AAPL.json') + return render(request, 'hackathon/quandl.html', {'everyData': everyData}) + ################# # NYTIMES API # @@ -494,21 +1468,26 @@ def quandlstocks(request): def nytimespop(request): '''Returns JSON response about the most viewed articles for the last 24 hours.''' - popdata = fetcharticle(settings.POPAPIKEY, 'http://api.nytimes.com/svc/mostpopular/v2/mostviewed/all-sections/1.json?') + popdata = fetcharticle(settings.POPAPIKEY, + 'http://api.nytimes.com/svc/mostpopular/v2/mostviewed/all-sections/1.json?') return JSONResponse({'data': popdata}) + def nytimestop(request): '''Returns JSON response about the articles located in the homepage''' topdata = fetcharticle(settings.TOPAPIKEY, 'http://api.nytimes.com/svc/topstories/v1/home.json?') return JSONResponse({'data': topdata}) + def nytimesarticles(request): everyData = {} - popdata = fetcharticle(settings.POPAPIKEY, 'http://api.nytimes.com/svc/mostpopular/v2/mostviewed/all-sections/1.json?') + popdata = fetcharticle(settings.POPAPIKEY, + 'http://api.nytimes.com/svc/mostpopular/v2/mostviewed/all-sections/1.json?') topdata = topdata = fetcharticle(settings.TOPAPIKEY, 'http://api.nytimes.com/svc/topstories/v1/home.json?') everyData['top'] = topdata everyData['pop'] = popdata - return render(request, 'hackathon/nytimes.html', { 'everyData': everyData }) + return render(request, 'hackathon/nytimes.html', {'everyData': everyData}) + ################# # GITHUB API # @@ -522,6 +1501,7 @@ def githubUser(request): parsedData['userData'] = getUserData(user, settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET) return render(request, 'hackathon/github.html', {'data': parsedData}) + def githubTopRepositories(request): '''Returns Top Commited Repositories for a specific Github User''' @@ -529,19 +1509,22 @@ def githubTopRepositories(request): if request.method == 'POST': user = request.POST.get('user') repositories = getUserRepositories(user, settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET) - list = getTopContributedRepositories(user, repositories, settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET) + list = getTopContributedRepositories(user, repositories, settings.GITHUB_CLIENT_ID, + settings.GITHUB_CLIENT_SECRET) filtered = filterCommits(list) parsedData['committed'] = filtered print parsedData return render(request, 'hackathon/githubTopRepositories.html', {'data': parsedData}) + def githubResume(request): '''A sample application which pulls various Github data to form a Resume of sorts''' allData = {} userData = getUserData('DrkSephy', settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET) repositories = getUserRepositories('DrkSephy', settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET) - list = getTopContributedRepositories('DrkSephy', repositories, settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET) + list = getTopContributedRepositories('DrkSephy', repositories, settings.GITHUB_CLIENT_ID, + settings.GITHUB_CLIENT_SECRET) filtered = filterCommits(list) stargazers = getStarGazerCount('DrkSephy', settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET) filteredStargazers = filterStarGazerCount(stargazers) @@ -550,7 +1533,7 @@ def githubResume(request): allData['filteredData'] = filtered allData['filteredStargazers'] = filteredStargazers allData['forkedRepos'] = forkedRepos - return render(request, 'hackathon/githubResume.html', { 'data': allData }) + return render(request, 'hackathon/githubResume.html', {'data': allData}) ################# @@ -560,14 +1543,14 @@ def githubResume(request): def tumblr(request): ''' Tumblr api calls ''' if getTumblr.is_authorized: - #get blogger twitterthecomic's blog information + # get blogger twitterthecomic's blog information blog = getTumblr.getBlogInfo('twitterthecomic') - #get tags that was tagged along starbucks + # get tags that was tagged along starbucks tagged_blog = getTumblr.getTaggedInfo("starbucks") - #get blog information tagged with starbucks + # get blog information tagged with starbucks blogontag = getTumblr.getTaggedBlog("starbucks") else: - blog, tagged_blog, blogontag = '', '','' + blog, tagged_blog, blogontag = '', '', '' global profile_track profile_track = 'tumblr' tumblr_url = getTumblr.authorize_url() @@ -588,42 +1571,45 @@ def instagram(request): if request.method == 'GET': if request.GET.items(): instagram_tag = request.GET.get('instagram_tag') - instagramUser = InstagramProfile.objects.get(user = request.user) + instagramUser = InstagramProfile.objects.get(user=request.user) tagged_media = getTaggedMedia(instagram_tag, instagramUser.access_token) else: instagram_tag, tagged_media = '', '' else: global profile_track profile_track = 'instagram' - instagram_url =getInstagram.get_authorize_url() + instagram_url = getInstagram.get_authorize_url() return HttpResponseRedirect(instagram_url) context = {'title': 'Instagram', 'tagged_media': tagged_media, 'search_tag': instagram_tag} return render(request, 'hackathon/instagram.html', context) + def instagramUser(request): ''' Returns JSON response about a specific Instagram User. ''' access_token = InstagramProfile.objects.get(instagram_user='mk200789').access_token parsedData = getUserInfo(access_token) - return JsonResponse({ 'data': parsedData }) + return JsonResponse({'data': parsedData}) + def instagramUserMedia(request): ''' Returns JSON response about a specific Instagram User's Media. ''' access_token = InstagramProfile.objects.get(instagram_user='mk200789').access_token parsedData = getUserMedia(32833691, access_token) - return JsonResponse({'data': parsedData }) + return JsonResponse({'data': parsedData}) + def instagramMediaByLocation(request): print request.user if request.method == 'GET': if request.GET.items(): - #check if user has a User profile + # check if user has a User profile if request.user in User.objects.all(): - #check if user has an Instagram profile + # check if user has an Instagram profile user = User.objects.get(username=request.user) - #if user has an Instagram profile, query the search + # if user has an Instagram profile, query the search if InstagramProfile.objects.all().filter(user=user.id): address = request.GET.get('address_field') access_token = InstagramProfile.objects.get(user=user.id).access_token @@ -634,12 +1620,13 @@ def instagramMediaByLocation(request): title = address err_msg = '' else: - title, media, err_msg, location_ids, geocode_result = 'Media by location','', str(request.user)+ ' does not have an InstagramProfile','', '' + title, media, err_msg, location_ids, geocode_result = 'Media by location', '', str( + request.user) + ' does not have an InstagramProfile', '', '' else: - title, media, err_msg, location_ids, geocode_result = 'Media by location', '','', '', '' + title, media, err_msg, location_ids, geocode_result = 'Media by location', '', '', '', '' - - context = {'title': title, 'geocode_result':geocode_result, 'media':media, 'list_id':location_ids, 'err_msg': err_msg} + context = {'title': title, 'geocode_result': geocode_result, 'media': media, 'list_id': location_ids, + 'err_msg': err_msg} return render(request, 'hackathon/instagram_q.html', context) @@ -656,9 +1643,10 @@ def twitter(request): twitter_url = getTwitter.get_authorize_url() return HttpResponseRedirect(twitter_url) - context ={'title': 'twitter', 'value': value} + context = {'title': 'twitter', 'value': value} return render(request, 'hackathon/twitter.html', context) + def twitterTweets(request): print getTwitter.is_authorized if getTwitter.is_authorized: @@ -674,7 +1662,7 @@ def twitterTweets(request): twitter_url = getTwitter.get_authorize_url() return HttpResponseRedirect(twitter_url) - context ={'title': 'twitter tweet', 'content': content, 'data': jsonlist} + context = {'title': 'twitter tweet', 'content': content, 'data': jsonlist} return render(request, 'hackathon/twitter_tweet.html', context) @@ -700,13 +1688,14 @@ def linkedin(request): ######################### class CRUDBaseView(mixins.ListModelMixin, - mixins.CreateModelMixin, - mixins.RetrieveModelMixin, - mixins.UpdateModelMixin, - mixins.DestroyModelMixin, - viewsets.GenericViewSet): + mixins.CreateModelMixin, + mixins.RetrieveModelMixin, + mixins.UpdateModelMixin, + mixins.DestroyModelMixin, + viewsets.GenericViewSet): pass + class SnippetView(CRUDBaseView): serializer_class = SnippetSerializer queryset = Snippet.objects.all() @@ -745,10 +1734,10 @@ def register(request): else: user_form = UserForm() - return render(request, - 'hackathon/register.html', - {'user_form': user_form, 'registered': registered} ) + 'hackathon/register.html', + {'user_form': user_form, 'registered': registered}) + def user_login(request): if request.method == 'POST': @@ -770,6 +1759,7 @@ def user_login(request): else: return render(request, 'hackathon/login.html', {}) + def user_logout(request): logout(request) return HttpResponseRedirect('/hackathon/login/') @@ -781,30 +1771,35 @@ def instagram_login(request): instagram_url = getInstagram.get_authorize_url() return HttpResponseRedirect(instagram_url) + def tumblr_login(request): global profile_track profile_track = 'tumblr' tumblr_url = getTumblr.authorize_url() return HttpResponseRedirect(tumblr_url) + def twitter_login(request): global profile_track profile_track = 'twitter' twitter_url = getTwitter.get_authorize_url() return HttpResponseRedirect(twitter_url) + def github_login(request): global profile_track profile_track = 'github' github_url = getGithub.get_authorize_url() return HttpResponseRedirect(github_url) + def linkedin_login(request): global profile_track profile_track = 'linkedin' linkedin_url = getLinkedIn.get_authorize_url() return HttpResponseRedirect(linkedin_url) + def facebook_login(request): global profile_track profile_track = 'facebook' @@ -818,14 +1813,42 @@ def google_login(request): google_url = getGoogle.get_authorize_url() return HttpResponseRedirect(google_url) + def dropbox_login(request): global profile_track profile_track = 'dropbox' dropbox_url = getDropbox.get_authorize_url() return HttpResponseRedirect(dropbox_url) + def foursquare_login(request): global profile_track profile_track = 'foursquare' forsquare_url = getFoursquare.get_authorize_url() return HttpResponseRedirect(forsquare_url) + + +def upload_file(request): + if request.method == 'POST': + form = UploadFileForm(request.POST, request.FILES) + if form.is_valid(): + return render(request, 'hackathon/upload_csv.html', { + 'uploaded_file_url': uploaded_file_url + }) + else: + form = UploadFileForm() + return render(request, 'hackathon/upload_csv.html', {'form': form}) + + +def csv_reader(request): + if request.method == 'POST': + paramFile = request.FILES['file'].read().split('\n') + photorequest = csv.DictReader(paramFile) + fieldnames = next(photorequest) + photorequest = csv.DictReader(paramFile, fieldnames=fieldnames) + next(photorequest) + a = [] + for row in photorequest: + a.append(row) + return render(request, 'hackathon/view_csv_requests.html', {'requests': a}) + return render(request, 'hackathon/upload_csv.html') diff --git a/hackathon_starter/hackathon_starter/settings.py b/hackathon_starter/hackathon_starter/settings.py old mode 100644 new mode 100755 index 7c081b5..4e2cd9d --- a/hackathon_starter/hackathon_starter/settings.py +++ b/hackathon_starter/hackathon_starter/settings.py @@ -42,6 +42,7 @@ 'django_nose', 'rest_framework', 'corsheaders', + 'bootstrap3', ) MIDDLEWARE_CLASSES = ( @@ -145,11 +146,11 @@ QUANDLAPIKEY = '' -FACEBOOK_APP_ID = '' -FACEBOOK_APP_SECRET = '' +FACEBOOK_APP_ID = '135096223749093' +FACEBOOK_APP_SECRET = 'c49859d6040baee88b578a8d1a5333fe' -GOOGLE_PLUS_APP_ID = '' -GOOGLE_PLUS_APP_SECRET = '' +GOOGLE_PLUS_APP_ID = '855088085720-3odqeigkm52orpsblhtfmc6lpean1lai.apps.googleusercontent.com' +GOOGLE_PLUS_APP_SECRET = 'wApSt2VOuZBq01czUcOVVpa1' DROPBOX_APP_ID = '' DROPBOX_APP_SECRET = '' diff --git a/hi.txt b/hi.txt new file mode 100644 index 0000000..45b983b --- /dev/null +++ b/hi.txt @@ -0,0 +1 @@ +hi