|
@@ -9,11 +9,14 @@ from django.contrib.auth import authenticate, login, logout
|
|
|
from django.contrib.auth.models import User
|
|
from django.contrib.auth.models import User
|
|
|
from django.contrib.auth.decorators import login_required
|
|
from django.contrib.auth.decorators import login_required
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
|
|
+from django.http import JsonResponse
|
|
|
|
|
|
|
|
# Scripts
|
|
# Scripts
|
|
|
from scripts.steam import gamesPulling, steamIDPulling
|
|
from scripts.steam import gamesPulling, steamIDPulling
|
|
|
from scripts.github import *
|
|
from scripts.github import *
|
|
|
-from scripts.tumblr import *
|
|
|
|
|
|
|
+from scripts.tumblr import TumblrOauthClient
|
|
|
|
|
+from scripts.twilioapi import *
|
|
|
|
|
+from scripts.instagram import InstagramOauthClient
|
|
|
|
|
|
|
|
# Python
|
|
# Python
|
|
|
import oauth2 as oauth
|
|
import oauth2 as oauth
|
|
@@ -21,71 +24,43 @@ from rest_framework.renderers import JSONRenderer
|
|
|
from rest_framework.parsers import JSONParser
|
|
from rest_framework.parsers import JSONParser
|
|
|
|
|
|
|
|
# Models
|
|
# Models
|
|
|
-from hackathon.models import Snippet
|
|
|
|
|
|
|
+from hackathon.models import Snippet, Profile
|
|
|
from hackathon.serializers import SnippetSerializer
|
|
from hackathon.serializers import SnippetSerializer
|
|
|
from hackathon.forms import UserForm
|
|
from hackathon.forms import UserForm
|
|
|
|
|
|
|
|
|
|
|
|
|
getTumblr = TumblrOauthClient(settings.TUMBLR_CONSUMER_KEY, settings.TUMBLR_CONSUMER_SECRET)
|
|
getTumblr = TumblrOauthClient(settings.TUMBLR_CONSUMER_KEY, settings.TUMBLR_CONSUMER_SECRET)
|
|
|
|
|
+getInstagram = InstagramOauthClient(settings.INSTAGRAM_CLIENT_ID, settings.INSTAGRAM_CLIENT_SECRET)
|
|
|
|
|
|
|
|
def index(request):
|
|
def index(request):
|
|
|
context = {'hello': 'world'}
|
|
context = {'hello': 'world'}
|
|
|
return render(request, 'hackathon/index.html', context)
|
|
return render(request, 'hackathon/index.html', context)
|
|
|
|
|
|
|
|
-def test(request):
|
|
|
|
|
- return HttpResponse('meow')
|
|
|
|
|
|
|
+##################
|
|
|
|
|
+# Twilio API #
|
|
|
|
|
+##################
|
|
|
|
|
|
|
|
-def api_examples(request):
|
|
|
|
|
- obtain_oauth_verifier = getTumblr.get_authorize_url()#simpleoauthurl(settings.TUMBLR_CONSUMER_KEY, settings.TUMBLR_CONSUMER_SECRET)
|
|
|
|
|
- context = {'title': 'API Examples Page', 'tumblr_url': obtain_oauth_verifier}
|
|
|
|
|
- return render(request, 'hackathon/api_examples.html', context)
|
|
|
|
|
-
|
|
|
|
|
-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
|
|
|
|
|
- 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)
|
|
|
|
|
|
|
+def twilio(request):
|
|
|
|
|
+ sendSMS('Meow', '+13473282978', '+13473781813')
|
|
|
|
|
+ return render(request, 'hackathon/twilio.html')
|
|
|
|
|
|
|
|
|
|
+##################
|
|
|
|
|
+# API Examples #
|
|
|
|
|
+##################
|
|
|
|
|
|
|
|
- if user:
|
|
|
|
|
- if user.is_active:
|
|
|
|
|
- login(request, user)
|
|
|
|
|
- return HttpResponseRedirect('/hackathon/')
|
|
|
|
|
- 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.")
|
|
|
|
|
-
|
|
|
|
|
|
|
+def api_examples(request):
|
|
|
|
|
+ instagram_url =getInstagram.get_authorize_url()
|
|
|
|
|
+ if not getTumblr.accessed:
|
|
|
|
|
+ obtain_oauth_verifier = getTumblr.authorize_url()
|
|
|
else:
|
|
else:
|
|
|
- return render(request, 'hackathon/login.html', {})
|
|
|
|
|
|
|
+ obtain_oauth_verifier = '/hackathon/tumblr'
|
|
|
|
|
+ #obtain_oauth_verifier = getTumblr.authorize_url()
|
|
|
|
|
+ context = {'title': 'API Examples Page', 'tumblr_url': obtain_oauth_verifier, 'instagram_url':instagram_url}
|
|
|
|
|
+ return render(request, 'hackathon/api_examples.html', context)
|
|
|
|
|
|
|
|
-def user_logout(request):
|
|
|
|
|
- logout(request)
|
|
|
|
|
- return HttpResponseRedirect('/hackathon/')
|
|
|
|
|
|
|
+#################
|
|
|
|
|
+# STEAM API #
|
|
|
|
|
+#################
|
|
|
|
|
|
|
|
def steam(request):
|
|
def steam(request):
|
|
|
#Should link to test of Steam API example.
|
|
#Should link to test of Steam API example.
|
|
@@ -95,7 +70,32 @@ def steam(request):
|
|
|
game = gamesPulling(steamID, key)
|
|
game = gamesPulling(steamID, key)
|
|
|
return render(request,'hackathon/steam.html', {"game": game })
|
|
return render(request,'hackathon/steam.html', {"game": game })
|
|
|
|
|
|
|
|
-def github(request):
|
|
|
|
|
|
|
+
|
|
|
|
|
+#################
|
|
|
|
|
+# GITHUB API #
|
|
|
|
|
+#################
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def githubUser(request):
|
|
|
|
|
+ '''Returns JSON response about a specific Github User'''
|
|
|
|
|
+
|
|
|
|
|
+ parsedData = {}
|
|
|
|
|
+ parsedData['userData'] = getUserData(settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET)
|
|
|
|
|
+ return JsonResponse({ 'data': parsedData })
|
|
|
|
|
+
|
|
|
|
|
+def githubTopRepositories(request):
|
|
|
|
|
+ '''Returns JSON response of a User's Top Committed repositories'''
|
|
|
|
|
+
|
|
|
|
|
+ parsedData = {}
|
|
|
|
|
+ repositories = getUserRepositories(settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET)
|
|
|
|
|
+ list = getTopContributedRepositories(repositories, settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET)
|
|
|
|
|
+ filtered = filterCommits(list)
|
|
|
|
|
+ parsedData['committed'] = filtered
|
|
|
|
|
+ return JsonResponse({ 'data': parsedData })
|
|
|
|
|
+
|
|
|
|
|
+def githubResume(request):
|
|
|
|
|
+ '''A sample application which pulls various Github data to form a Resume of sorts'''
|
|
|
|
|
+
|
|
|
allData = {}
|
|
allData = {}
|
|
|
userData = getUserData(settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET)
|
|
userData = getUserData(settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET)
|
|
|
repositories = getUserRepositories(settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET)
|
|
repositories = getUserRepositories(settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET)
|
|
@@ -108,30 +108,103 @@ def github(request):
|
|
|
allData['filteredData'] = filtered
|
|
allData['filteredData'] = filtered
|
|
|
allData['filteredStargazers'] = filteredStargazers
|
|
allData['filteredStargazers'] = filteredStargazers
|
|
|
allData['forkedRepos'] = forkedRepos
|
|
allData['forkedRepos'] = forkedRepos
|
|
|
-
|
|
|
|
|
return render(request, 'hackathon/github.html', { 'data': allData })
|
|
return render(request, 'hackathon/github.html', { 'data': allData })
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+#################
|
|
|
|
|
+# TUMBLR API #
|
|
|
|
|
+#################
|
|
|
|
|
+
|
|
|
def tumblr(request):
|
|
def tumblr(request):
|
|
|
''' Tumblr api calls '''
|
|
''' Tumblr api calls '''
|
|
|
- #retrieve verifier via url link
|
|
|
|
|
- if not request.GET.items():
|
|
|
|
|
- return HttpResponseRedirect('/hackathon/api/')
|
|
|
|
|
- else:
|
|
|
|
|
- getTumblr.get_access_token_url(request.GET.get('oauth_verifier'))
|
|
|
|
|
- #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")
|
|
|
|
|
- context = {'title': "What's up Starbucks?", 'blogData': blog, 'blogTag': tagged_blog, 'blogontag': blogontag}
|
|
|
|
|
- return render(request, 'hackathon/tumblr.html', context)
|
|
|
|
|
|
|
+ if not getTumblr.accessed:
|
|
|
|
|
+ oauth_verifier = request.GET.get('oauth_verifier')
|
|
|
|
|
+ getTumblr.access_token_url(oauth_verifier)
|
|
|
|
|
+ if request.user not in User.objects.all():
|
|
|
|
|
+ try:
|
|
|
|
|
+ user_info, total_blog = getTumblr.getUserInfo()
|
|
|
|
|
+ username = str(user_info['name'])+ "2"
|
|
|
|
|
+ user = User.objects.get(username=username)
|
|
|
|
|
+ except User.DoesNotExist:
|
|
|
|
|
+ user_info, total_blog = getTumblr.getUserInfo()
|
|
|
|
|
+ username = str(user_info['name'])+ "2"
|
|
|
|
|
+ new_user = User.objects.create_user(username, username+'@example.com','password')
|
|
|
|
|
+ new_user.save()
|
|
|
|
|
+ profile =Profile()
|
|
|
|
|
+ profile.user = new_user
|
|
|
|
|
+ profile.oauth_token = getTumblr.oauth_token
|
|
|
|
|
+ profile.oauth_secret = getTumblr.oauth_token_secret
|
|
|
|
|
+ profile.save()
|
|
|
|
|
+
|
|
|
|
|
+ user = authenticate(username=username, password='password')
|
|
|
|
|
+ login(request, user)
|
|
|
|
|
+
|
|
|
|
|
+ #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")
|
|
|
|
|
+
|
|
|
|
|
+ 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):
|
|
|
|
|
+ code = request.GET['code']
|
|
|
|
|
+ getInstagram.get_access_token(code)
|
|
|
|
|
+
|
|
|
|
|
+ if request.user not in User.objects.all():
|
|
|
|
|
+ try:
|
|
|
|
|
+ user = User.objects.get(username=getInstagram.user_data['username'] )
|
|
|
|
|
+ except User.DoesNotExist:
|
|
|
|
|
+ username = getInstagram.user_data['username']
|
|
|
|
|
+ new_user = User.objects.create_user(username, username+'@example.com', 'password')
|
|
|
|
|
+ new_user.save()
|
|
|
|
|
+ profile = Profile()
|
|
|
|
|
+ profile.user = new_user
|
|
|
|
|
+ profile.oauth_token = getInstagram.client_id
|
|
|
|
|
+ #since instagram doesnt have oauth_secret value, using this field to temp set in access token
|
|
|
|
|
+ # for JSON response
|
|
|
|
|
+ profile.oauth_secret = getInstagram.access_token
|
|
|
|
|
+ profile.save()
|
|
|
|
|
+
|
|
|
|
|
+ user = authenticate(username=getInstagram.user_data['username'], password='password')
|
|
|
|
|
+ login(request, user)
|
|
|
|
|
+
|
|
|
|
|
+ search_tag = 'kitten'
|
|
|
|
|
+ #return tagged objects
|
|
|
|
|
+ tagged_media = getInstagram.get_tagged_media(search_tag)
|
|
|
|
|
+ context = {'title': 'Instagram', 'tagged_media': tagged_media, 'search_tag': search_tag}
|
|
|
|
|
+ return render(request, 'hackathon/instagram.html', context)
|
|
|
|
|
+
|
|
|
|
|
+def instagramUser(request):
|
|
|
|
|
+ '''Returns JSON response about a specific Instagram'''
|
|
|
|
|
+
|
|
|
|
|
+ user_id = User.objects.get(username='mk200789').id
|
|
|
|
|
+ access_token = Profile.objects.get(user=user_id).oauth_secret
|
|
|
|
|
+ parsedData = getInstagram.get_user_info(access_token)
|
|
|
|
|
+ return JsonResponse({ 'data': parsedData })
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+##################
|
|
|
|
|
+# LINKED IN API #
|
|
|
|
|
+##################
|
|
|
|
|
|
|
|
def linkedin(request):
|
|
def linkedin(request):
|
|
|
userinfo = getUserInfo()
|
|
userinfo = getUserInfo()
|
|
|
context = {'title': 'linkedin Example','userdata': userinfo}
|
|
context = {'title': 'linkedin Example','userdata': userinfo}
|
|
|
return render(request, 'hackathon/linkedin.html', context)
|
|
return render(request, 'hackathon/linkedin.html', context)
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+#########################
|
|
|
|
|
+# Snippet RESTful Model #
|
|
|
|
|
+#########################
|
|
|
|
|
+
|
|
|
class JSONResponse(HttpResponse):
|
|
class JSONResponse(HttpResponse):
|
|
|
"""
|
|
"""
|
|
|
An HttpResponse that renders its content into JSON.
|
|
An HttpResponse that renders its content into JSON.
|
|
@@ -151,3 +224,59 @@ def snippet_list(request):
|
|
|
serializer = SnippetSerializer(snippets, many=True)
|
|
serializer = SnippetSerializer(snippets, many=True)
|
|
|
return JSONResponse(serializer.data)
|
|
return JSONResponse(serializer.data)
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+######################
|
|
|
|
|
+# 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
|
|
|
|
|
+ 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/')
|
|
|
|
|
+ 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/')
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def instagram_login(request):
|
|
|
|
|
+ instagram_url =getInstagram.get_authorize_url()
|
|
|
|
|
+ return HttpResponseRedirect(instagram_url)
|
|
|
|
|
+
|
|
|
|
|
+def tumblr_login(request):
|
|
|
|
|
+ tumblr_url = getTumblr.authorize_url()
|
|
|
|
|
+ return HttpResponseRedirect(tumblr_url)
|