Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d4de3f4
Showing
29 changed files
with
3,091 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
application: toohipster | ||
version: 1 | ||
runtime: python | ||
api_version: 1 | ||
|
||
handlers: | ||
- url: .* | ||
script: main.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from google.appengine.api import urlfetch | ||
from django.utils import simplejson | ||
import logging | ||
class BitLy(): | ||
def __init__(self, login, apikey): | ||
self.login = login | ||
self.apikey = apikey | ||
|
||
def shorten(self,param): | ||
url = param | ||
request = "http://api.bit.ly/v3/shorten?longUrl=" | ||
request += url | ||
request += "&login=" + self.login + "&apiKey=" +self.apikey | ||
result = urlfetch.fetch(request) | ||
json = simplejson.loads(result.content) | ||
return json |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
indexes: | ||
|
||
# AUTOGENERATED | ||
|
||
# This index.yaml is automatically updated whenever the dev_appserver | ||
# detects that a new type of query is run. If you want to manage the | ||
# index.yaml file manually, remove the above marker line (the line | ||
# saying "# AUTOGENERATED"). If you want to manage some indexes | ||
# manually, move them above the marker line. The index.yaml file is | ||
# automatically uploaded to the admin console when you next deploy | ||
# your application using appcfg.py. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Copyright 2007 Google Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
import logging | ||
import tweepy | ||
import os | ||
|
||
from google.appengine.ext import webapp | ||
from google.appengine.ext.webapp import util | ||
from django.utils import simplejson as json | ||
from google.appengine.api import urlfetch | ||
from google.appengine.ext import db | ||
from bitly import BitLy | ||
|
||
|
||
|
||
|
||
TWITTER_CALLBACK = 'http://localhost:8080/callback' | ||
|
||
#TWITTER_CALLBACK = 'http://toohipster.appspot.com/callback' | ||
|
||
TWITTER_CONSUMER_KEY ='IFbmxlrnvIuKOtXiMEyEQ' | ||
TWITTER_CONSUMER_SECRET ='Xhe2NOEWWY0ZWxzb8K5x5NUg22gyuwN4sgvCg9o0XY' | ||
|
||
TWITTER_ACCESS_TOKEN='220091954-A1N3me3vSpiAavMVE73h6PevkDqPWOtyDlnKLjXN' | ||
TWITTER_ACCESS_TOKEN_SECRET='mDa8HBjD38J6xUbe61aSaGC62ej0OLAK8Vn0Tc2HQP8' | ||
|
||
BITLY_API_KEY = 'R_1ff412d8c04003ecdc217f821cd76183' | ||
BITLY_LOGIN = 'robee' | ||
|
||
class Song(db.Model): | ||
song_artist = db.StringProperty(required=True) | ||
rank = db.IntegerProperty(required=True) | ||
url = db.StringProperty(required=True) | ||
|
||
|
||
class MainHandler(webapp.RequestHandler): | ||
def get(self): | ||
|
||
results = urlfetch.fetch(url='http://query.yahooapis.com/v1/public/yql?q=SELECT%20alt%2C%20src%20FROM%20html%20WHERE%0Aurl%3D%22http%3A%2F%2Fwww.bbc.co.uk%2Fradio1%2Fchart%2Fsingles%2F%22%20AND%20xpath%3D%22%2F%2Fli%2Fimg%22%20LIMIT%20100&format=json&diagnostics=true&callback=cbfunc', | ||
payload='', | ||
method=urlfetch.GET, | ||
headers={}) | ||
|
||
|
||
results = results.content | ||
results = results.replace('cbfunc(', '').replace(');', '') | ||
|
||
results = json.loads(results)['query']['results']['img'] | ||
|
||
|
||
current_songs = Song.all() | ||
count = 0 | ||
for result in results: | ||
count = count+1 | ||
song = Song( song_artist = result['alt'], rank = count, url = result['src']) | ||
logging.info(result['src']) | ||
if is_song_in_db(song.song_artist) == 0: | ||
message = buildMessage(song) | ||
tweet(message) | ||
song.put() | ||
|
||
#tweet('TestTweet') | ||
|
||
self.response.out.write('You arent supposed to be here') | ||
|
||
|
||
class CallbackHandler(webapp.RequestHandler): | ||
def get(self): | ||
|
||
self.response.out.write('callback') | ||
|
||
|
||
def is_song_in_db(song_artist): | ||
|
||
songs = Song.all().fetch(100) | ||
|
||
for song in songs: | ||
if song_artist == song.song_artist: | ||
return 1 | ||
|
||
return 0 | ||
|
||
def buildMessage(song): | ||
|
||
#result[] | ||
#bitly = BitLy(BITLY_LOGIN, BITLY_API_KEY) | ||
#urlData = bitly.shorten(song.url) | ||
#shortURL = urlData['data']['url'] | ||
message = song.song_artist + ' - is too mainstream to be "Hipster"' | ||
return message | ||
|
||
def tweet(msg): | ||
|
||
auth = tweepy.OAuthHandler(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET) | ||
auth.set_access_token(TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_TOKEN_SECRET) | ||
|
||
api = tweepy.API(auth_handler=auth, secure=True, retry_count=5) | ||
|
||
api.update_status(msg) # post the tweet | ||
|
||
|
||
|
||
|
||
def main(): | ||
application = webapp.WSGIApplication([('/', MainHandler), ('/callback', CallbackHandler)], | ||
debug=True) | ||
util.run_wsgi_app(application) | ||
|
||
|
||
#{u'status_code': 200, u'data': {u'url': u'http://bit.ly/gahzrM', u'hash': u'gahzrM', u'global_hash': u'fmwBAN', u'long_url': u'http://robotandgunshot.com', u'new_hash': 0}, u'status_txt': u'OK'} | ||
|
||
|
||
pass | ||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Tweepy | ||
# Copyright 2009-2010 Joshua Roesslein | ||
# See LICENSE for details. | ||
|
||
""" | ||
Tweepy Twitter API library | ||
""" | ||
__version__ = '1.7.1' | ||
__author__ = 'Joshua Roesslein' | ||
__license__ = 'MIT' | ||
|
||
from tweepy.models import Status, User, DirectMessage, Friendship, SavedSearch, SearchResult, ModelFactory | ||
from tweepy.error import TweepError | ||
from tweepy.api import API | ||
from tweepy.cache import Cache, MemoryCache, FileCache | ||
from tweepy.auth import BasicAuthHandler, OAuthHandler | ||
from tweepy.streaming import Stream, StreamListener | ||
from tweepy.cursor import Cursor | ||
|
||
# Global, unauthenticated instance of API | ||
api = API() | ||
|
||
def debug(enable=True, level=1): | ||
|
||
import httplib | ||
httplib.HTTPConnection.debuglevel = level | ||
|
Binary file not shown.
Oops, something went wrong.