David Leonard 10 éve
szülő
commit
4c6391d394

+ 20 - 20
hackathon_starter/hackathon/scripts/meetup.py

@@ -8,27 +8,27 @@ import simplejson as json
 USERDATA = 'https://api.meetup.com/2/member/self/?access_token='
 
 def retrieveUserData(url):
-	req = requests.get(url)
-	content = json.loads(req.content)
-	filteredData = []
-	data = {}
-	data['name'] = content['name']
-	data['country'] = content['country'].upper()
-	data['city'] = content['city']
-	data['state'] = content['state']
-	data['status'] = content['status']
-	filteredData.append(data)
-	return filteredData
+    req = requests.get(url)
+    content = json.loads(req.content)
+    filteredData = []
+    data = {}
+    data['name'] = content['name']
+    data['country'] = content['country'].upper()
+    data['city'] = content['city']
+    data['state'] = content['state']
+    data['status'] = content['status']
+    filteredData.append(data)
+    return filteredData
 
 def retrieveDashboard(url):
-	req = requests.get(url)
-	content = json.loads(req.content)
-	filteredData = []
-	data = {}
-	data['last_event'] = content['last_event']['venue']
-	data['group'] = content['last_event']['group']['name']
-	data['name'] = content['last_event']['name']
-	filteredData.append(data)
-	return filteredData
+    req = requests.get(url)
+    content = json.loads(req.content)
+    filteredData = []
+    data = {}
+    data['last_event'] = content['last_event']['venue']
+    data['group'] = content['last_event']['group']['name']
+    data['name'] = content['last_event']['name']
+    filteredData.append(data)
+    return filteredData
 
 

+ 6 - 5
hackathon_starter/hackathon/scripts/nytimes.py

@@ -12,10 +12,11 @@ def fetcharticle(apikey, url):
     data = json.loads(req.content)
     parsedData = []
     for datum in data['results']:
-        new_data = {"title": datum["title"],
-                "abstract": datum["abstract"],
-                "section": datum["section"],
-                "byline": datum["byline"],
-                }
+        new_data = {
+            "title": datum["title"],
+            "abstract": datum["abstract"],
+            "section": datum["section"],
+            "byline": datum["byline"],
+        }
         parsedData.append(new_data)
     return parsedData

+ 98 - 98
hackathon_starter/hackathon/scripts/scraper.py

@@ -8,111 +8,111 @@ import itertools
 from bs4 import BeautifulSoup
 
 def fetchHTML(url):
-	'''
-	Returns HTML retrived from a url.
+    '''
+    Returns HTML retrived from a url.
 
-	Parameters:
-		url: String
-			- The URL to fetch HTML from
+    Parameters:
+        url: String
+            - The URL to fetch HTML from
 
-	Returns:
-		html: String
-			- The HTML from a given URL
-	'''
-	req = requests.get(url)
-	html = req.text
-	return html
+    Returns:
+        html: String
+            - The HTML from a given URL
+    '''
+    req = requests.get(url)
+    html = req.text
+    return html
 
 def extractTag(content, tag, className=None):
-	'''
-	Returns data embed within a tag, along
-	with an optional class for filtering.
-
-	Parameters:
-		content: String
-			- The HTML to parse
-		tag: String
-			- The HTML tag to scan for
-		class: String
-			- Optional filter for tag
-
-	Returns:
-		filteredData: List
-			- Content embed within searched tags
-	'''
-	soup = BeautifulSoup(content)
-	data = soup.findAll(tag, { 'class': className })
-	filteredData = []
-	for datum in data:
-		filteredData.append(datum.text)
-	return filteredData
+    '''
+    Returns data embed within a tag, along
+    with an optional class for filtering.
+
+    Parameters:
+        content: String
+            - The HTML to parse
+        tag: String
+            - The HTML tag to scan for
+        class: String
+            - Optional filter for tag
+
+    Returns:
+        filteredData: List
+            - Content embed within searched tags
+    '''
+    soup = BeautifulSoup(content)
+    data = soup.findAll(tag, { 'class': className })
+    filteredData = []
+    for datum in data:
+        filteredData.append(datum.text)
+    return filteredData
 
 
 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
+    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
 
 
 

+ 131 - 131
hackathon_starter/hackathon/scripts/tumblr.py

@@ -11,137 +11,137 @@ request_token_url   = 'http://www.tumblr.com/oauth/request_token'
 authorize_url       = 'http://www.tumblr.com/oauth/authorize'
 access_token_url    = 'http://www.tumblr.com/oauth/access_token'
 
-user_uri			= "http://api.tumblr.com/v2/user/info"
-blog_uri			= "http://api.tumblr.com/v2/blog/"
+user_uri            = "http://api.tumblr.com/v2/user/info"
+blog_uri            = "http://api.tumblr.com/v2/blog/"
 
 class TumblrOauthClient(object):
 
-	token = None
-	oauth_verifier = None
-	oauth_token = None
-	oauth_token_secret = None
-	accessed = False
-
-
-
-	def __init__(self, consumer_key, consumer_secret):
-		self.consumer_key = consumer_key
-		self.consumer_secret = consumer_secret
-		self.consumer = oauth2.Consumer(consumer_key, consumer_secret)
-		
-
-
-	def authorize_url(self):
-		client = oauth2.Client(self.consumer)
-		resp, content = client.request(request_token_url, "GET")
-		#parse content
-		if not self.oauth_token:
-			request_token = dict(urlparse.parse_qsl(content))
-			self.oauth_token = request_token['oauth_token'] #'QBXdeeMKAnLzDbIG7dDNewTzRYyQoHZLbcn3bAFTCEFF5EXurl' #
-			self.oauth_token_secret = request_token['oauth_token_secret']#'u10SuRl2nzS8vFK4K7UPQexAvbIFBFrZBjA79XDlgoXFxv9ZhO' #
-		link = authorize_url+"?oauth_token="+self.oauth_token+"&redirect_uri=http%3A%2F%2Flocalhost%3A8000/hackathon/tumblr"
-		return link
-
-
-	def access_token_url(self, oauth_verifier=''):
-		self.accessed = True
-		token = oauth2.Token(self.oauth_token, self.oauth_token_secret)
-		self.oauth_verifier = oauth_verifier
-		print self.oauth_verifier
-		token.set_verifier(self.oauth_verifier)
-		client = oauth2.Client(self.consumer, token)
-		resp, content = client.request(access_token_url,"POST")
-		access_token = dict(urlparse.parse_qsl(content))
-		#set verified token
-		self.token = oauth2.Token(access_token['oauth_token'], access_token['oauth_token_secret'])
-		#print self.token
-			
-
-
-	def getUserInfo(self):
-		''' Returns users information. '''
-		client = oauth2.Client(self.consumer, self.token)
-		#print client
-		resp, content = client.request(user_uri, "POST")
-		if int(resp['status']) != 200:
-			raise Exception("Invalid response %s." % resp['status'])
-
-		#return content in json format
-		jsonlist = json.loads(content)
-		response = jsonlist['response']
-		user_info = response['user']
-		total_blogs = len(user_info['blogs'])
-		#print user_info
-		return user_info, total_blogs
-
-
-	def getBlogInfo(self, user):
-		''' Returns blogger's blog information '''
-		blog_info = blog_uri + user + ".tumblr.com/info?api_key="+self.consumer_key
-		req = requests.get(blog_info)
-		
-		#if int(req.status_code) != 200:
-		#	raise Exception("Invalid response %s." % resp['status'])
-		
-
-		jsonlist = json.loads(req.content)
-		response = jsonlist['response']
-		blog 	 = response['blog']
-		blog['updated'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(blog['updated']))
-		return blog
-
-
-	def getTaggedInfo(self, tag):
-		''' Return tags related to blog with certain tag. '''
-
-		tagged_uri = "http://api.tumblr.com/v2/tagged?tag="+tag+"&api_key="+self.consumer_key+"&limit=20"
-		req = requests.get(tagged_uri)
-		jsonlist = json.loads(req.content)
-
-		tags = []
-
-		meta = jsonlist['meta']
-		body = jsonlist['response']
-		for blog in body:
-			for data in blog:
-				if data == "tags":
-					#print blog[data]
-					for i in blog[data]:
-						m = re.match("(.*)(s*)s(t*)t(a*)a(r*)r(b*)b(u*)u(c*)c(k*)k(.*)", i.lower())
-						if not m:
-							tags.append(i)					
-
-		return tags	
-
-
-	def getTaggedBlog(self, tag):
-		''' Return the tagged blogs's captions or post.'''
-		
-		tagged_uri = "http://api.tumblr.com/v2/tagged?tag="+tag+"&api_key="+self.consumer_key+"&limit=20"
-		req = requests.get(tagged_uri)
-		jsonlist = json.loads(req.content)
-		
-		meta = jsonlist['meta']
-		body = jsonlist['response']
-
-		tagtext = []
-
-		for blog in body:
-			#print "####"
-			for data in blog:
-				#post
-				if data == "body":
-					if blog[data]:
-						#print blog[data]
-						soup = BeautifulSoup(blog[data])
-						text = soup.get_text()
-						tagtext.append(text)
-				#an image
-				if data == "caption":
-					if blog[data]:
-						#print blog[data]
-						soup = BeautifulSoup(blog[data])
-						text = soup.get_text()					
-						tagtext.append(text)
-		
-		return tagtext
+    token = None
+    oauth_verifier = None
+    oauth_token = None
+    oauth_token_secret = None
+    accessed = False
+
+
+
+    def __init__(self, consumer_key, consumer_secret):
+        self.consumer_key = consumer_key
+        self.consumer_secret = consumer_secret
+        self.consumer = oauth2.Consumer(consumer_key, consumer_secret)
+        
+
+
+    def authorize_url(self):
+        client = oauth2.Client(self.consumer)
+        resp, content = client.request(request_token_url, "GET")
+        #parse content
+        if not self.oauth_token:
+            request_token = dict(urlparse.parse_qsl(content))
+            self.oauth_token = request_token['oauth_token'] #'QBXdeeMKAnLzDbIG7dDNewTzRYyQoHZLbcn3bAFTCEFF5EXurl' #
+            self.oauth_token_secret = request_token['oauth_token_secret']#'u10SuRl2nzS8vFK4K7UPQexAvbIFBFrZBjA79XDlgoXFxv9ZhO' #
+        link = authorize_url+"?oauth_token="+self.oauth_token+"&redirect_uri=http%3A%2F%2Flocalhost%3A8000/hackathon/tumblr"
+        return link
+
+
+    def access_token_url(self, oauth_verifier=''):
+        self.accessed = True
+        token = oauth2.Token(self.oauth_token, self.oauth_token_secret)
+        self.oauth_verifier = oauth_verifier
+        print self.oauth_verifier
+        token.set_verifier(self.oauth_verifier)
+        client = oauth2.Client(self.consumer, token)
+        resp, content = client.request(access_token_url,"POST")
+        access_token = dict(urlparse.parse_qsl(content))
+        #set verified token
+        self.token = oauth2.Token(access_token['oauth_token'], access_token['oauth_token_secret'])
+        #print self.token
+            
+
+
+    def getUserInfo(self):
+        ''' Returns users information. '''
+        client = oauth2.Client(self.consumer, self.token)
+        #print client
+        resp, content = client.request(user_uri, "POST")
+        if int(resp['status']) != 200:
+            raise Exception("Invalid response %s." % resp['status'])
+
+        #return content in json format
+        jsonlist = json.loads(content)
+        response = jsonlist['response']
+        user_info = response['user']
+        total_blogs = len(user_info['blogs'])
+        #print user_info
+        return user_info, total_blogs
+
+
+    def getBlogInfo(self, user):
+        ''' Returns blogger's blog information '''
+        blog_info = blog_uri + user + ".tumblr.com/info?api_key="+self.consumer_key
+        req = requests.get(blog_info)
+        
+        #if int(req.status_code) != 200:
+        #   raise Exception("Invalid response %s." % resp['status'])
+        
+
+        jsonlist = json.loads(req.content)
+        response = jsonlist['response']
+        blog     = response['blog']
+        blog['updated'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(blog['updated']))
+        return blog
+
+
+    def getTaggedInfo(self, tag):
+        ''' Return tags related to blog with certain tag. '''
+
+        tagged_uri = "http://api.tumblr.com/v2/tagged?tag="+tag+"&api_key="+self.consumer_key+"&limit=20"
+        req = requests.get(tagged_uri)
+        jsonlist = json.loads(req.content)
+
+        tags = []
+
+        meta = jsonlist['meta']
+        body = jsonlist['response']
+        for blog in body:
+            for data in blog:
+                if data == "tags":
+                    #print blog[data]
+                    for i in blog[data]:
+                        m = re.match("(.*)(s*)s(t*)t(a*)a(r*)r(b*)b(u*)u(c*)c(k*)k(.*)", i.lower())
+                        if not m:
+                            tags.append(i)                  
+
+        return tags 
+
+
+    def getTaggedBlog(self, tag):
+        ''' Return the tagged blogs's captions or post.'''
+        
+        tagged_uri = "http://api.tumblr.com/v2/tagged?tag="+tag+"&api_key="+self.consumer_key+"&limit=20"
+        req = requests.get(tagged_uri)
+        jsonlist = json.loads(req.content)
+        
+        meta = jsonlist['meta']
+        body = jsonlist['response']
+
+        tagtext = []
+
+        for blog in body:
+            #print "####"
+            for data in blog:
+                #post
+                if data == "body":
+                    if blog[data]:
+                        #print blog[data]
+                        soup = BeautifulSoup(blog[data])
+                        text = soup.get_text()
+                        tagtext.append(text)
+                #an image
+                if data == "caption":
+                    if blog[data]:
+                        #print blog[data]
+                        soup = BeautifulSoup(blog[data])
+                        text = soup.get_text()                  
+                        tagtext.append(text)
+        
+        return tagtext

+ 1 - 1
hackathon_starter/hackathon/scripts/yelp.py

@@ -9,7 +9,7 @@ TOKEN = 'AWYVs7Vim7mwYyT1BLJA2xhNTs_vXLYS'
 TOKEN_SECRET = 'Rv4GrlYxYGhxUs14s0VBfk7JLJY'
 
 def requestData():
-    url = 'http://api.yelp.com/v2/business/marlowe-san-francisco-2?'
+    url = 'http://api.yelp.com/v2/business/yelp-san-francisco?'
 
     consumer = oauth2.Consumer(CONSUMER_KEY, CONSUMER_SECRET)
     oauth_request = oauth2.Request(method="GET", url=url)