def get_feed_app_Net(): feed_name = 'App.Net' if debug: print 'APP_NET_ACCESS_TOKEN: ' + APP_NET_ACCESS_TOKEN scope = ['messages'] api = appdotnet(access_token=APP_NET_ACCESS_TOKEN, messages) searchResults = api.getUserStream() jsonResults = json.loads(searchResults.encode('utf-8')) if debug: help(jsonResults[0])
def get_feed_app_Net(): feed_name = 'App.Net' if debug: print 'APP_NET_ACCESS_TOKEN: ' + APP_NET_ACCESS_TOKEN scope = ['messages'] api = appdotnet(access_token=APP_NET_ACCESS_TOKEN) searchResults = json.loads(api.getGlobalStream().encode('utf-8')) jsonResults = searchResults['data'] if debug: for item in jsonResults: print item['text']
def get_feed_app_net(): if debug: print 'Feed Name: App.net' print 'APP_NET_ACCESS_TOKEN: ' + APP_NET_ACCESS_TOKEN api = appdotnet(access_token=APP_NET_ACCESS_TOKEN) # get the globalStream and change the encoding to utf-8 from unicode streamResults = json.loads(api.getGlobalStream().encode('utf-8')) jsonResults = streamResults['data'] if debug: print json.dumps(jsonResults, indent=4, separators=[',', ':']) return jsonResults
def setup_api_connections(): global twitter_api global app_net_api global TWITTER_CONSUMER_KEY global TWITTER_CONSUMER_SECRET global TWITTER_ACCESS_TOKEN_KEY global TWITTER_ACCESS_TOKEN_SECRET global user_to_mirror global APP_NET_CLIENT_ID global APP_NET_CLIENT_SECRET global APP_NET_CALLBACK_URL global APP_NET_ACCESS_TOKEN global APP_NET_SCOPE print "Setting up API connections..." # first let's do twitter # can't proceed without all of the twitter credentials if TWITTER_CONSUMER_KEY \ and TWITTER_CONSUMER_SECRET \ and TWITTER_ACCESS_TOKEN_KEY \ and TWITTER_ACCESS_TOKEN_SECRET \ and user_to_mirror: twitter_api = twitter.Api( consumer_key=TWITTER_CONSUMER_KEY, consumer_secret=TWITTER_CONSUMER_SECRET, access_token_key=TWITTER_ACCESS_TOKEN_KEY, access_token_secret=TWITTER_ACCESS_TOKEN_SECRET ) verification = twitter_api.VerifyCredentials() if verification: print "Twitter authentication was successful." else: print "Error: There was a problem authenticating with Twitter." print "Please check your credentials and try again." sys.exit(1) else: print "Error: missing one or more Twitter credentials." print "Please check config and try again." sys.exit(1) # Now let's do App.net # This is a bit trickier, there are two possible states # We NEED client_id, client_secret and callback_url if APP_NET_CLIENT_ID \ and APP_NET_CLIENT_SECRET \ and APP_NET_CALLBACK_URL: # now if there is a access_token, just use it to authenticate if not APP_NET_ACCESS_TOKEN: # we need to authenticate app_net_api = appdotnet(APP_NET_CLIENT_ID,APP_NET_CLIENT_SECRET,APP_NET_CALLBACK_URL,APP_NET_SCOPE) url = app_net_api.generateAuthUrl() print "App.net auth url: %s" % url print "Browse to that url, then paste the url you get redirected to here." redirect_string = raw_input(':') m = re.search('^.*code=(.+?)$', redirect_string) if m: found = m.group(1) response_json = app_net_api.getAuthResponse(found) response_object = json.loads(response_json) access_token = response_object["access_token"] print "Your access token is:" print access_token print "Save this value in your configuration file (or otherwise make a note" print "of it) and re-run this script." sys.exit(0) else: print "HEY, something is wrong, could not find the access code!" sys.exit(1) else: app_net_api = appdotnet(access_token=APP_NET_ACCESS_TOKEN) if app_net_api: print "App.net authentication successful." else: print "Unable to authenticate with App.net" sys.exit(1) else: print "Error: missing one or more App.net credentials." print "Please check config and try again." sys.exit(1)
from appdotnet import * import praw, time #Set a user agent, this can be your app name or a description of your app. r = praw.Reddit(user_agent='USERAGENT') #Obviously, put your own access token here. If you don't have a developer account, grab a token from Dev Lite, thanks @duerig app = appdotnet(access_token="token") already_done = set() #Get the submissions and post them to App.net while True: l = r.get_top(limit=1) submission = next(l,None) if not submission: continue while submission.id in already_done: submission=next(r.get_front_page(limit=1, params={'before':"t3_"+submission.id }),None) if not submission: break if submission: id = submission.id title = submission.title url = submission.short_link if title.count > 100: title = title[0:100] + ".."
from appdotnet import * import praw, time, urllib #Set a user agent, this can be your app name or a description of your app. r = praw.Reddit(user_agent="USERAGENT") #Obviously, put your own access token here. If you don't have a developer account, grab a token from Dev Lite, thanks @duerig app = appdotnet(access_token="authtoken") already_done = set() def duplicate_check(id): found = 0 with open('posted_posts.txt', 'r') as file: for line in file: if id in line: found = 1 return found def add_id_to_file(id): with open('posted_posts.txt', 'a') as file: file.write(str(id) + "\n") #Get the submissions and post them to App.net while urllib.urlopen("http://reddit.com/").getcode() == 200: l = r.get_top(limit=1) submission = next(l,None) if not submission: continue