Browse Source

Merged DrkSephy/django-hackathon-starter into default

Eswari Pravallika Swarna 10 years ago
parent
commit
3633ee7d36

+ 16 - 3
README.md

@@ -22,7 +22,7 @@ In order to run this project, do the following:
 
 ## Front End dependencies
 
-This project relies on Bower for all front end libraries, to avoid pushing up large libraries such as `jQuery` and `Bootstrap`. To install `bower`, you will need to install `npm`, which now comes bundled with `node.js`. To install `npm`, simply install [node as follows](https://github.com/joyent/node/wiki/installing-node.js-via-package-manager). 
+This project relies on Bower for all front end libraries, to avoid pushing up large libraries such as `jQuery` and `Bootstrap`. **Under no circumstance should any front-end libraries manually be pushed up to the repository.** To install `bower`, you will need to install `npm`, which now comes bundled with `node.js`. To install `npm`, simply install [node as follows](https://github.com/joyent/node/wiki/installing-node.js-via-package-manager). 
 
 First, install `bower`:
 
@@ -33,7 +33,7 @@ Then:
     # In the same directory as requirements.txt
     bower install
 
-This will download and extract all the packages listed within `bower.json`. **Under no circumstance should any front-end libraries manually be pushed up to the repository.**
+This will download and extract all the packages listed within `bower.json`. 
 
 Then:
 
@@ -63,7 +63,7 @@ In order to write clean code with a consistent style guide, we'll be using `Pyli
 
 ## RESTful endpoints
 
-Using the `Django REST framework, the current RESTful endpoints exist:
+Using the `Django REST framework`, the current RESTful endpoints exist:
 
     http://127.0.0.1:8000/hackathon/snippets/
 
@@ -83,6 +83,14 @@ The list will appear empty at first, since the database model `Snippets` will be
 
 The above will open the Django shell, and allow you to create objects and save them to the database. If you then navigate to the URL above, you will see the JSON output of the database model, `Snippet`. 
 
+## Django JSON Response Endpoints
+
+As of `Django 1.7x`, there is a new method called `JsonResponse` which allows the user to send JSON data to a URL which makes it available to be consumed by any client. The following endpoints exist:
+
+* `http://127.0.0.1:8000/hackathon/steamDiscountedGames/`: JSON output containing steam discounts data
+* `http://127.0.0.1:8000/hackathon/instagramUser/`: JSON output containing data from an Instagram user through OAuth
+* `http://127.0.0.1:8000/hackathon/githubUser/`: JSON output containing data from a Github User
+
 ## AngularJS Client
 
 As of `April 11th, 2015`, there is now a sample AngularJS client which pulls data from the Django sample API endpoint: `http://127.0.0.1:8000/hackathon/snippets/`. To test it, do the following:
@@ -90,6 +98,11 @@ As of `April 11th, 2015`, there is now a sample AngularJS client which pulls dat
 * Within the `public/` directory, run `python -m SimpleHTTPServer 80`. You may need `sudo` on your respective Operating System.
 * Navigate to: `http://localhost/#/snippets`. Here you will see whatever content was stored within the database model, `Snippet`. If nothing shows up, go back to the `RESTful endpoints` step to populate your database with some `Snippet` objects. 
 
+The following other links are available on the AngularJS Client:
+
+* `http://localhost/#/githubUser`: Pulls JSON response for Github data from Django 
+* `http://localhost/#/steamSales`: Pulls JSON response for Steam sales data from Django
+
 ## Ionic Client
 
 As of `April 11th, 2015`, there is now a sample Ionic application which works on iOS. This application pulls data from the Django sample API endpoint: `http://127.0.0.1:8000/hackathon/snippets/`. In order to successfully run this project, you must do the following:

+ 2 - 0
angular/index.html

@@ -26,11 +26,13 @@
         <script src="scripts/controllers/restAppController.js"></script>
         <script src="scripts/controllers/githubUserController.js"></script>
         <script src="scripts/controllers/githubTopContributionsController.js"></script>
+        <script src="scripts/controllers/steamSalesController.js"></script>
 
         <!-- Factories -->
         <script src="scripts/factories/restAppFactory.js"></script>
         <script src="scripts/factories/githubUserFactory.js"></script>
         <script src="scripts/factories/githubTopContributionsFactory.js"></script>
+        <script src="scripts/factories/steamSalesFactory.js"></script>
 
     </head>
 

+ 29 - 0
angular/partials/steamSales.partial.html

@@ -0,0 +1,29 @@
+<div class="row text-center"> 
+    <h1> Latest Steam Sale Data </h1>
+</div>
+
+<div class="col-lg-12">
+    <div class="table-responsive">
+        <table class="table table-bordered table-hover table-striped tablesorter">
+            <thead>
+                <tr>
+                    <th class="header">Name</th>
+                    <th class="header">Release Date</th>
+                    <th class="header">Discount</th>
+                    <th class="header">Price</th>
+                </tr>
+            </thead>
+            <tbody>
+                <tr data-ng-repeat="data in steamSales.data ">
+                        <td>{{ data.name }}</td>
+                        <td>{{ data.releaseDates }}</td>
+                        <td>{{ data.discount }} </td>
+                        <td>{{ data.price }}</td>
+                </tr>
+            </tbody>
+        </table>
+    </div>
+</div>
+
+
+

+ 9 - 0
angular/scripts/app.js

@@ -23,6 +23,15 @@ var restApp = angular.module('restApp', [
             }
         })
 
+        .state('steamSales', {
+            url: '/steamSales',
+            templateUrl: 'partials/steamSales.partial.html',
+            controller: 'steamSalesController',
+            data: {
+                pageTitle: 'Latest Steam Sales'
+            }
+        })
+
         .state('githubTopContributions', {
             url: '/githubTopContributions',
             templateUrl: 'partials/githubTopContributions.partial.html',

+ 10 - 0
angular/scripts/controllers/steamSalesController.js

@@ -0,0 +1,10 @@
+'use strict';
+
+restApp.controller('steamSalesController', function($scope, steamSalesFactory) {
+    $scope.steamSales= {};
+    
+    $scope.steamSales = steamSalesFactory.get().success(function(data) {
+    	$scope.steamSales = data;
+    	console.log(data);
+    });
+});

+ 12 - 0
angular/scripts/factories/steamSalesFactory.js

@@ -0,0 +1,12 @@
+'use strict';
+
+restApp.factory('steamSalesFactory', function($http) {
+    return {
+        get: function() {
+            return $http({
+                url: 'http://127.0.0.1:8000/hackathon/steamDiscountedGames/',
+                method: 'GET',
+            });
+        }
+    };
+});

+ 74 - 0
hackathon_starter/hackathon/scripts/scraper.py

@@ -0,0 +1,74 @@
+import requests
+from bs4 import BeautifulSoup
+import itertools 
+
+def steamDiscounts():
+	req = requests.get('http://store.steampowered.com/search/?specials=1#sort_by=_ASC&sort_order=ASC&specials=1&page=1')
+	content = req.text
+	soup = BeautifulSoup(content)
+	allData = {id: {} for id in range(0, 25)}
+
+
+	# Get all divs of a specific class
+	releaseDate = soup.findAll('div', {'class': 'col search_released'})
+
+	# Get all release dates
+	releaseDates = []
+	id = 0
+	for date in releaseDate:
+		allData[id]['releaseDates'] = date.text
+		releaseDates.append(date.text)
+		id += 1
+
+	#print releaseDates
+
+	id = 0
+	gameName = soup.findAll('div', {'class': 'col search_name ellipsis'})
+
+	# Get all game names
+	gameNames = []
+	for name in gameName:
+		span = name.findAll('span', {'class': 'title'})
+		for tag in span:
+			allData[id]['name'] = tag.text
+			gameNames.append(tag.text)
+			id += 1
+
+	# print gameNames
+
+	discount = soup.findAll('div', {'class': 'col search_discount'})
+
+	id = 0
+	# Get all game discounts 
+	gameDiscounts = []
+	for discountedGame in discount:
+		span = discountedGame.findAll('span')
+		for tag in span:
+			allData[id]['discount'] = tag.text
+			gameDiscounts.append(tag.text)
+			id += 1
+
+	# print gameDiscounts
+
+	price = soup.findAll('div', {'class': 'col search_price discounted'})
+
+	id = 0
+	prices = []
+	# Get all discounted prices
+	for value in price:
+		br = value.findAll('br')
+		for tag in br:
+			allData[id]['price'] = tag.text.strip('\t')
+			prices.append(tag.text.strip('\t'))
+			id += 1
+
+	# Cleanup data
+	newData = []
+	for datum in allData:
+		newData.append(allData[datum])
+	# print prices
+	return newData
+
+
+
+

+ 1 - 0
hackathon_starter/hackathon/urls.py

@@ -9,6 +9,7 @@ urlpatterns = patterns('',
     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'),

+ 5 - 0
hackathon_starter/hackathon/views.py

@@ -17,6 +17,7 @@ from scripts.github import *
 from scripts.tumblr import TumblrOauthClient
 from scripts.twilioapi import *
 from scripts.instagram import InstagramOauthClient
+from scripts.scraper import steamDiscounts
 
 # Python
 import oauth2 as oauth
@@ -71,6 +72,10 @@ def steam(request):
     return render(request,'hackathon/steam.html', {"game": game })
 
 
+def steamDiscountedGames(request):
+    data = steamDiscounts()
+    return JsonResponse({ 'data': data })
+
 #################
 #   GITHUB API  #
 #################

+ 19 - 0
ionic/www/js/app.js

@@ -46,6 +46,25 @@ angular.module('starter', ['ionic', 'starter.controllers'])
     }
   })
 
+  .state('app.instagramUser',{
+    url: "/instagramUser",
+    views: {
+      'menuContent': {
+        templateUrl: 'templates/instagramUser.html',
+        controller: 'instagramUserCtrl'
+      }
+    }
+  })
+
+  .state('app.steamSales', {
+    url: '/steamSales',
+    views: {
+      'menuContent': {
+        templateUrl: 'templates/steamSales.html',
+        controller: 'steamSalesCtrl'
+      }
+    }
+  });
   // if none of the above states are matched, use this as the fallback
   $urlRouterProvider.otherwise('/app/snippets');
 });

+ 8 - 0
ionic/www/js/controllers.js

@@ -12,3 +12,11 @@ angular.module('starter.controllers', ['starter.services'])
     $scope.githubUserData = githubUser.get();
 })
 
+.controller('instagramUserCtrl', function($scope, instagramUser){
+	$scope.instagramUserData = instagramUser.get();
+})
+
+.controller('steamSalesCtrl', function($scope, steamSales){
+	$scope.sales = steamSales.get();
+});
+

+ 8 - 0
ionic/www/js/services.js

@@ -6,4 +6,12 @@ angular.module('starter.services', ['ngResource'])
 
 .factory('githubUser', function ($resource) {
     return $resource('http://127.0.0.1:8000/hackathon/githubUser/');
+})
+
+.factory('instagramUser', function ($resource){
+	return $resource('http://localhost:8000/hackathon/instagramUser/');
+})
+
+.factory('steamSales', function ($resource){
+	return $resource('http://127.0.0.1:8000/hackathon/steamDiscountedGames/');
 })

+ 1 - 1
ionic/www/templates/githubUser.html

@@ -5,7 +5,7 @@
   <ion-content class="has-header">
 
   
-    	<ion-item ng-repeat="data in githubUserData .data.userData">
+    	<ion-item ng-repeat="data in githubUserData.data.userData">
     		<div class="col">Name: {{ data.name }}</div>
 			  <div class="col">Public Repos: {{ data.public_repos }}</div>
 			  <div class="col">Public Gists: {{ data.public_gists }}</div>

+ 18 - 0
ionic/www/templates/instagramUser.html

@@ -0,0 +1,18 @@
+<ion-view title="Instagram User Data">
+  <ion-nav-buttons side="left">
+      <button menu-toggle="left" class="button button-icon icon ion-navicon"></button>
+  </ion-nav-buttons>
+  <ion-content class="has-header">
+
+    	<ion-item ng-repeat="data in instagramUserData">
+    		<div class="col">Username: {{ data.username }}</div>
+			  <div class="col">Full name: {{ data.fullname }}</div>
+        <div class="col">Bio: {{ data.bio }}</div>
+			  <div class="col">Website: {{ data.website }}</div>
+			  <div class="col">Followers: {{ data.counts.followed_by}}</div>
+			  <div class="col">Following: {{ data.counts.follows }}</div>
+			  <div class="col">Media: {{ data.counts.media }}</div>
+    	</ion-item>
+  
+  </ion-content>
+</ion-view>

+ 6 - 0
ionic/www/templates/menu.html

@@ -24,6 +24,12 @@
         <ion-item nav-clear menu-close href="#/app/githubUser">
             Github User 
         </ion-item>
+        <ion-item nav-clear menu-close href="#/app/instagramUser">
+            Instagram User 
+        </ion-item> 
+        <ion-item nav-clear menu-close href="#/app/steamSales">
+            Steam Sales 
+        </ion-item>       
       </ion-list>
     </ion-content>
   </ion-side-menu>

+ 17 - 0
ionic/www/templates/steamSales.html

@@ -0,0 +1,17 @@
+<ion-view title="Latest Steam Sale Data">
+  <ion-nav-buttons side="left">
+      <button menu-toggle="left" class="button button-icon icon ion-navicon"></button>
+  </ion-nav-buttons>
+  <ion-content class="has-header">
+    <ion-item ng-repeat="data in sales.data">
+        <div class="col">Name: {{ data.name }}</div>
+        <div class="col">Release Date: {{ data.releaseDates }}</div>
+        <div class="col">Discount: {{ data.discount }}</div>
+        <div class="col">Price: {{ data.price }} </div>
+    </ion-item>
+
+ 
+
+  
+  </ion-content>
+</ion-view>