예제 #1
0
def reset_settings():
    settings = json_to_dict("/resources/settings.json")
    write_to_json("/resources/settings_recover.json", settings)

    if argv[1] == "-a" or argv[1] == "--auth":
        settings["auth"]["api private key"] = ""
        settings["auth"]["api public key"] = ""
        settings["auth"]["token private key"] = ""
        settings["auth"]["token public key"] = ""

    settings["canvas"]["margin"] = 0.1
    settings["canvas"]["size"]["height"] = 1080
    settings["canvas"]["size"]["width"] = 1080

    settings["image-data"]["filetype"] = "jpg"
    settings["image-data"]["quality"] = 100

    settings["text"]["characters per line"] = 40
    settings["text"]["font"] = "/fonts/Roboto-Medium.ttf"
    settings["text"]["font-size"] = 44
    settings["text"]["hashtags"][
        "cities to search"] = "/resources/list_of_cities.txt"
    settings["text"]["hashtags"]["keywords"] = "/resources/keywords.txt"
    settings["text"]["hashtags"]["searchspace"] = 10
    settings["text"]["hashtags"]["woeids"] = "/resources/woeid.json"
    settings["text"]["horizontal align"] = "left"
    settings["text"]["shadow offset"] = 2
    settings["text"]["text from source"] = "/resources/bible_verses.txt"
    settings["text"]["vertical align"] = "top"

    write_to_json("/resources/settings.json", settings)
def fill_header_with_emojis(header, meme_amplitude, settings):
    # Retrieves a dictionary of emojis and their probability-distribution.
    emoji_dict = json_to_dict('/resources/emojis.json')

    # Takes the actual tweet and splits it into a list.
    split_header = header.split()

    hashtag = get_hashtags(settings)

    # Number of allowed characters in a tweet.
    max_chars = 240

    # Remaining number of characters allowed in a tweet.
    remaining_chars = max_chars - len(
        ''.join(split_header)) - (meme_amplitude * 2) - len(hashtag)

    # Average emojis per word in tweet
    avg = remaining_chars / (len(split_header))

    emoji_keys = list(emoji_dict.keys())
    emoji_values = list(emoji_dict.values())
    premojis = ''.join(
        numpy.choice(emoji_keys, size=meme_amplitude, p=emoji_values))
    postmojis = ''.join(
        numpy.choice(emoji_keys, size=meme_amplitude, p=emoji_values))
    emojified_message = ''

    # If tweet is to long to add emojis between words
    if avg < 1:
        returnstring = premojis + header + postmojis

    else:
        for i, word in enumerate(split_header, 1):
            emojified_message += word
            # Don't add emojis behind last word, postmojis covers this.
            if i == len(split_header):
                break
            # Insert random number of emojis if average is less than 5
            for i in range(randint(1, int(avg) if avg < 5 else 5)):
                # Replace with function returning emojis relative to probability
                emojified_message += ''.join(
                    numpy.choice(emoji_keys, size=1, p=emoji_values))

    returnstring = premojis + emojified_message + postmojis + ' ' + hashtag
    return returnstring
예제 #3
0
    hashtag_woeids = []
    for i, city in enumerate(cities):
        for woeid in woeids:
            if woeid["city"] == city:
                hashtag_woeids.append(woeid["woeid"])
                break
        if i > searchspace:
            break

    api = twitter_object(settings)

    for woeid in hashtag_woeids:
        response = api.trends_place(woeid)
        all_hashtags = [
            trend["name"] for trend in response[0]["trends"]
            if trend["name"][0] == '#'
        ]

        for keyword in keywords:
            for hashtag in all_hashtags:
                # Some advanced Regex would be fantastic here.
                if keyword in hashtag and hashtag not in hashtags:
                    hashtags.append(hashtag)

    return choice(hashtags)


if __name__ == "__main__":
    get_hashtags(json_to_dict('/resources/settings.json'))
예제 #4
0
import sys
import os
from random import randint
from time import time, sleep
from bot import bot
from pre_processing import select_quote, get_img, json_to_dict
from image_processing import put_quote_on_wallpaper
from tweet_processing import create_header
import logger

if __name__ == '__main__':
    # Starts timer
    start = time()

    # Load settings
    settings = json_to_dict("/resources/settings.json")

    # Selects a verse from the bible
    verse, verse_index = select_quote()

    # Retrieves an image.
    pic_num = get_img(settings)

    # Processes bible-verse onto image.
    put_quote_on_wallpaper(sys.path[0] + '/resources/photo_of_the_day.jpg',
                           verse, settings)

    # Creates tweet-header
    tweet, header_index = create_header(settings)

    # Uploads image and tweet-header to twitter
예제 #5
0
    for key, val in dct.items():
        i_li.append(val * (len(dct)))

    percentage_li = create_probability_distribution(i_li)

    percentage_dict[elem] = percentage_li[0]
    for i, (key, val) in enumerate(dct.items()):
        i += 1
        percentage_dict['0001' + key] = percentage_li[i]

    return percentage_dict


if __name__ == '__main__':
    if len(argv) > 1:
        json_file = sys.path[0] + '/resources/emojis.json'
        dict_emoji = json_to_dict(json_file)
        try:
            if argv[1] == 'add':
                emoji = argv[2]
                value = int(argv[3])
                dct = append_emoji(dict_emoji, emoji, value)
            elif argv[1] == 'rm':
                del dict_emoji[argv[2]]
                dct = dict_emoji

            write_to_json(json_file, dct)
        except:
            print(
                'Unknown parameter. Format: admin_emoji.py \{emoji} \{value}')
예제 #6
0
def recover_settings():
    settings = json_to_dict("/resources/settings_recover.json")
    write_to_json("/resources/settings.json", settings)