Ejemplo n.º 1
0
    def post_twitter_thread(self):
        payload = self._get_payload()

        if len(payload) > 1:
            th = Threader(payload, self.api, wait=2, end_string=False)
            th.send_tweets()

        return payload
Ejemplo n.º 2
0
def tweet_it():

    from lib.commom import keysANDapi, ipstack_key, rpi, bt

    # actually make tweets
    tweets = bt(rpi, ipstack_key)

    # used to send tweets
    from threader import Threader

    # send tweets
    th = Threader(tweets, keysANDapi, wait=2, end_string=False)
    th.send_tweets()

    # print tweet id's to console
    print(th.tweet_ids_)
Ejemplo n.º 3
0
def post_tweets():

    json_data = request.get_json()  # Get tweets from twitter.js
    tweets_array = json_data["tweets"]

    thread_keys = dict(consumer_key=key,
                       consumer_secret=secret,
                       access_token_key=a_token,
                       access_token_secret=a_token_secret)

    thread_api = TwitterAPI(**thread_keys)

    # tweets_array MUST be a list
    th = Threader(tweets_array, thread_api, wait=1)
    th.send_tweets()

    return {'screen_name': screen_name}
from pytz import timezone
from googletrans import Translator
from threader import Threader

date = datetime.now()
timezone = timezone("America/Sao_Paulo")
full_date = date.astimezone(timezone)
formatted_date = full_date.strftime("Data: %d/%m/%Y às %H:%M")

continents = [
    'Ásia', 'Austrália / Oceania', 'África', 'Europa', 'América do Norte',
    'América do Sul', 'Mundo'
]

for continent in continents:

    objects = Scrapping.get_continent_info(continent)
    objects.sort(key=attrgetter("total_cases"), reverse=True)

    thread = [obj.data_text for obj in objects[:15]]

    thread_thumb = f"""     Atualizações do #Coronavírus - {objects[0].continent}\n\n
                    {formatted_date}\n\n
                    \u26A0\uFE0FDetalhes na thread\u26A0\uFE0F"""

    thread.insert(0, thread_thumb)

    thread_maker = Threader(thread, api, wait=5, end_string=False)
    thread_maker.send_tweets()
    time.sleep(60)
Ejemplo n.º 5
0
 def send_tweet(self):
     thread = Threader(self._tweets, self.api, wait=2)
     thread.send_tweets()
Ejemplo n.º 6
0
def nextTweet():
    try:
        if canTweet:
            apiKey = twConfig['tokens']['apiKey']
            apiSecret = twConfig['tokens']['apiSecret']
            accessToken = twConfig['tokens']['accessToken']
            accessTokenSecret = twConfig['tokens']['accessTokenSecret']
            api = Twython(apiKey, apiSecret, accessToken, accessTokenSecret)

        sourceFile = fConfig['files']['sourceFile']
        targetFile = fConfig['files']['targetFile']

        if canTweet == False:
            sourceFile = 'C:\\Users\\mrbar\\Documents\\visual studio 2017\\Projects\\Birdfeeder\\Birdfeeder\\toTweet.txt'
            targetFile = 'C:\\Users\\mrbar\\Documents\\visual studio 2017\\Projects\\Birdfeeder\\Birdfeeder\\tweeted.txt'

        #Open feed file
        with open(sourceFile, 'r') as f:
            wholeLine = f.readline()
            wholeLine = wholeLine.strip("\n")
        f.closed
        if wholeLine.strip() == "":
            print('nothing to tweet')
            return 0

#Break up text into Tweet Thread
        threadParts = []
        threadCount = 0
        threadParts = ['']
        words = wholeLine.split(' ')
        for word in words:
            if len(threadParts[threadCount] + word) <= 140:
                threadParts[
                    threadCount] = threadParts[threadCount] + ' ' + word
            else:
                threadCount = threadCount + 1
                threadParts.append(word)

        if canTweet:
            #api.update_status(status=wholeLine)
            th = Threader(tweets, api, wait=2)
            th.send_tweets()
        else:
            for threadPart in threadParts:
                print('TWEET: ' + threadPart)

        #open target file
        if os.path.exists(targetFile) == False:
            f = open(targetFile, 'w+')
            f.closed
        with open(targetFile, 'a') as f:
            fts = datetime.datetime.now().strftime('%a, %d/%B/%Y %I:%M%p')
            f.writelines(fts + ': ' + wholeLine + "\n")
        f.closed

        #Remove line from source
        tempfilename = '/media/usb/' + datetime.datetime.now().strftime(
            '%Y%B%d%I%M') + '.txt'
        with open(sourceFile, "r") as input:
            with open(tempfilename, "w+") as output:
                for line in input:
                    if line.strip("\n") != wholeLine:
                        output.write(line)
        os.remove(sourceFile)
        os.rename(tempfilename, sourceFile)

        return 1

    except BaseException as err:
        print('error:', err)
        return 0
Ejemplo n.º 7
0
wrapped_n = [ l + f'  [{n+1}/{t}]' for n, l in enumerate(wrapped)]

with open('mod_prop_tweetable.txt', 'wt') as f:
    f.writelines(l + '\n' for l in wrapped_n)

with open('mod_prop_tweetable.txt') as f:
    wrapped_n = [line.rstrip() for line in f]

# personal details
consumer_key = os.environ.get("TWITTER_API_KEY")
consumer_secret = os.environ.get("TWITTER_API_SECRET_KEY")
access_token = os.environ.get("TWITTER_ACCESS_TOKEN")
access_token_secret = os.environ.get("TWITTER_ACCESS_TOKEN_SECRET")

# authentication of consumer key and secret
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)

# authentication of access token and secret
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)

tweets = [f"A MODEST THREAD   [0/{t}]"]
tweets.extend(wrapped_n)

username = None
th = Threader(tweets, api, wait=1, user=username, end_string=False)
print(th)

th.send_tweets() # This where is gets to the real world.

Ejemplo n.º 8
0
def send_tweet():
    print("send tweet")
    tweet_array = wrap(tweet.value, 240)
    th = Threader(tweet_array, api, wait=slider.value)
    th.send_tweets()