def cache_article(self, share_url=None, corry_id=None): result = requests.get(share_url) if result.status_code == 200: self.parse_article(result.content) if self.title: self.corry_id = corry_id self.share_url = share_url self.insert() print("\nNew article: %s - %s" % (self.corry_id, self.title)) Tweeter().send_tweet(self) return self
def main(): print("Welcome to my nonary game....\n") authDict = getAuthOptions() if isinstance(authDict, str): print("Unable to get authorization tokens, please try again") return tweeterer = Tweeter(authDict["token"], authDict["secret"]) pause = input("wait until it says account set please") say_what = input("What do we say? ") whom = input("tweet at someone? ") tweet = "@%s %s" % (whom, say_what) to_send = input("do you want to send this tweet?") if to_send == "yes": tweeterer.send_tweet(tweet) '''
import time from card import Card from querent import Querent from reading import Reading from tarotdb import TarotDB from tweeter import Tweeter import os from os import environ CONSUMER_KEY = os.environ.get('CONSUMER_KEY') CONSUMER_SECRET = os.environ.get('CONSUMER_SECRET') ACCESS_KEY = os.environ.get('ACCESS_KEY') ACCESS_SECRET = os.environ.get('ACCESS_SECRET') db = TarotDB("diviner.db") tw = Tweeter(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_KEY, ACCESS_SECRET) querents = Querent() for q in querents.get_querents(): reading = Reading(db, q) tweet = reading.get_reading() tw.tweet(tweet)
def main(): """ Tweeter object and related credentials """ tweeter = Tweeter() # c_key = '' # c_secret = '' # a_token = '' # a_secret = '' """ Login to twitter using above credentials """ # tweeter.login(c_key, c_secret, a_token, a_secret) try: load = sys.argv[1] except Exception: Utility.error('main', 'Error in passed parameters.') """ Create MarkovModel object to formulate tweets """ model = MarkovModel() try: # Load a already saved model if load in ['-l', '-L']: filename, keyword, prefix, suffix, n_tweets = load_params() Utility.log('main', 'Loading model from file {0}'.format(filename)) model.load('../model/m_blk_{0}'.format(filename)) tweeter.start_tweeting(time=1, keywords=keyword.split(), prefix=prefix, suffix=suffix) tweeter._autoconstruct(model, int(n_tweets)) # Carve up a dictionary from read elif load in ['-r', '-R']: filename, keyword, prefix, suffix, n_tweets = load_params() Utility.log( 'main', 'Training model from file {0}, and saving.'.format(filename)) model.read('../data/{0}.txt'.format(filename)) model.save('../model/m_blk_{0}'.format(filename.split('.')[0])) tweeter.start_tweeting(time=1, keywords=keyword.split(), prefix=prefix, suffix=suffix) tweeter._autoconstruct(model, int(n_tweets)) # Collect tweets and store to a database elif load in ['-c', '-C']: no = sys.argv[2] Utility.log( 'main', 'Collecting {0} tweets and saving them to db.'.format(no)) tweets = tweeter.read_tweets(int(no)) Tweeter.store(tweets) # Load a number of tweets and amplify elif load in ['-a', '-A']: no = sys.argv[2] timeout = sys.argv[3] Utility.log( 'main', 'Tweeting {0} tweets every {1} seconds'.format(no, timeout)) tweeter.amplify_tweets(int(no), int(timeout)) else: Utility.error('main', 'Invalid parameters') Utility.log('main', 'Exiting program ...') except KeyboardInterrupt: Utility.log('main', 'Terminating program ...')
#!/usr/bin/python3 import handlers import watchdog from breath_analyzer import BreathAnalyzer from camera import Obscura from tweeter import Tweeter if __name__ == "__main__": with watchdog.get_connection_to_arduino() as serialConn: serialConn.read_until('SPS='.encode()) samples_per_second = float(serialConn.readline()) handler = handlers.OnThresholdExceededHandler( '/common/stream', Tweeter(), Obscura('/dev/video0', (640, 480)), serialConn, status_maker=lambda datetime, value, message: "{}\nThe value measured was {:.1f} units, at {}.".format( message, value, datetime.strftime("%X on %x"))) breathAnalyzer = BreathAnalyzer( samples_per_second, handler, on_reset=lambda: serialConn.write('Sensor is ready'.encode())) watchdog.keep_reading(serialConn, breathAnalyzer.add_gas_concentration)
from flask import Flask, render_template from tweeter import Tweeter import os app = Flask(__name__) tweetObject = Tweeter("#MLHLocalhost",20) tweetObject.scrapeTweets() @app.route('/') def homepage(): return render_template('index.html', tweets=tweetObject.getTweets()) port = int(os.environ.get('PORT', 5000)) app.run(host='0.0.0.0', port=port, debug=True)
def main(): """ main the main driver code which logs into using the twitter credintials and executes the script according to the given modifier Options: -l : Load model from file. Use this if using an existing model. Filename : Name of pickle file to load markov model. Keywords : Seedwords which are an intergral part of tweet. Keywords may be single or multiple. Prefix : Word/s to start the tweet with. Prefix may be single or multiple words. Suffix : Word/s to add at the end of tweet. Suffix may be single or multiple words. num_tweets : Number of tweets to be written. -r : Read file to create model. Use this if including your own text file. Filename : Name of text file to construct markov model. Keywords : Seedwords which are an intergral part of tweet. Keywords may be single or multiple. Prefix : Word/s to start the tweet with. Prefix may be single or multiple words. Suffix : Word/s to add at the end of tweet. Suffix may be single or multiple words. num_tweets : Number of tweets to be written. -c : Collect tweets from TwitterStream. no : Number of tweets to collect. -a : Amplify tweets i.e. Retweet tweets stored using -c. no : Number of tweets to amplify. timeout : Time to wait in seconds before retweeting. logs into the twitter using the given credentials. If there is error it catches the exception and returns an exception message """ tweeter = Tweeter() # c_key = '' # c_secret = '' # a_token = '' # a_secret = '' # tweeter.login(c_key, c_secret, a_token, a_secret) try: load = sys.argv[1] except Exception: Utility.error('main', 'Error in passed parameters.') # Create MarkovModel object to formulate tweets model = MarkovModel() try: # Load a already saved model if load in ['-l', '-L']: filename, keyword, prefix, suffix, n_tweets = load_params() Utility.log('main', 'Loading model from file {0}'.format(filename)) model.load('../model/m_blk_{0}'.format(filename)) tweeter.start_tweeting( time=1, keywords=keyword.split(), prefix=prefix, suffix=suffix) tweeter._autoconstruct(model, int(n_tweets)) # Carve up a dictionary from read elif load in ['-r', '-R']: filename, keyword, prefix, suffix, n_tweets = load_params() Utility.log( 'main', 'Training model from file {0}, and saving.'.format(filename)) model.read('../data/{0}.txt'.format(filename)) model.save('../model/m_blk_{0}'.format(filename.split('.')[0])) tweeter.start_tweeting( time=1, keywords=keyword.split(), prefix=prefix, suffix=suffix) tweeter._autoconstruct(model, int(n_tweets)) # Collect tweets and store to a database elif load in ['-c', '-C']: no = sys.argv[2] Utility.log( 'main', 'Collecting {0} tweets and saving them to db.'.format(no)) tweets = tweeter.read_tweets(int(no)) Tweeter.store(tweets) # Load a number of tweets and amplify elif load in ['-a', '-A']: no = sys.argv[2] timeout = sys.argv[3] Utility.log( 'main', 'Tweeting {0} tweets every {1} seconds'.format(no, timeout)) tweeter.amplify_tweets(int(no), int(timeout)) else: Utility.error('main', 'Invalid parameters') Utility.log('main', 'Exiting program ...') except KeyboardInterrupt: Utility.log('main', 'Terminating program ...')
# Camera warm-up time time.sleep(preview_time) camera.capture(stream, 'jpeg') return stream def watermark(filename, msg): img = Image.open(filename) draw = ImageDraw.Draw(img) font = ImageFont.truetype('roboto/Roboto-Regular.ttf', 36) draw.text((10, 10), msg, (0, 0, 0), font=font) img.save(filename) if (__name__ == "__main__"): preview_time = 1 stream = read_image(preview_time) filename = "image.jpg" with open(filename, 'wb') as file: file.write(stream.getvalue()) cpu = CpuTemp() msg = "CPU temp: " + cpu.read() + "C" watermark(filename, msg) if config["tweet"] == True: tweeter = Tweeter(config, tweepy) tweeter.send( filename, "Internet of Seeds Mark II - https://github.com/alexellis/seeds2")