예제 #1
0
파일: bot.py 프로젝트: mitch3b/NesWRBot
def postWrs(wrs, withTTL):
    tweetCount = 0
    discordCount = 0

    for speedrun in wrs:
        try:
            if not stored_values.runWasAlreadyDiscorded(speedrun.runId):
                discorder.post(speedrun)
                stored_values.markRunAlreadyDiscorded(speedrun.runId, withTTL)
                discordCount += discordCount
        except Exception as err:
            print("Issue posting wr {} to discord with err: {}".format(
                speedrun, err))

        try:
            if not stored_values.runWasAlreadyTweeted(speedrun.runId):
                tweeter.tweet(speedrun)
                stored_values.markRunAlreadyTweeted(speedrun.runId, withTTL)
                tweetCount += tweetCount
        except Exception as err:
            print("Issue posting wr {} to twitter with err: {}".format(
                speedrun, err))

    print(
        "Done posting {0} world records to twitter and {1} to discord.".format(
            tweetCount, discordCount))
예제 #2
0
파일: bot.py 프로젝트: d-baker/bots
def bot():
    current_word = ""
    with open ("resources/everyword.txt") as fp:
        current_word = fp.readline().strip().decode("utf-8")
    tweet(umlautify(current_word))
    # if tweeting fails the current word shouldn't get deleted
    with open("resources/everyword.txt", "r") as fin:
        words = fin.read().splitlines(True)
    with open("resources/everyword.txt", "w") as fout:
        fout.writelines(words[1:])
예제 #3
0
파일: drowyreve.py 프로젝트: d-baker/bots
def drowyreve():
    current_word = ""
    with open ("resources/drowyreve.txt") as fp:
        current_word = fp.readline().strip().decode("utf-8")
    tweet(current_word[::-1])
    # if tweeting fails the current word shouldn't get deleted
    with open("resources/drowyreve.txt", "r") as fin:
        words = fin.read().splitlines(True)
    with open("resources/drowyreve.txt", "w") as fout:
        fout.writelines(words[1:])
예제 #4
0
def main():
    global count
    global lasttime
    global testing

    num_frames = None
    num_objects = 8  # just for debug printing

    # Forced sensor mode, 1640x1232, full FoV. use mode 4, was using frame rate of 10
    # https://picamera.readthedocs.io/en/release-1.13/fov.html#sensor-modes
    # kevinh 3280x2464 is mode 3 (but that is too large for twitter)
    with PiCamera(sensor_mode=4, framerate=3) as camera:
        camera.awb_mode = 'sunlight'
        camera.exposure_mode = 'sports'
        # if out of memory err occurs see https://stackoverflow.com/questions/39251815/python-not-taking-picture-at-highest-resolution-from-raspberry-pi-camera
        camera.resolution = (1920, 1080)

        with CameraInference(
                image_classification.model(
                    image_classification.MOBILENET)) as inference:
            for result in inference.run(num_frames):
                classes = image_classification.get_classes(result)
                newclasses = list(filter(removeold, classes))
                if newclasses:
                    print(classes_info(newclasses, num_objects))
                    name = newclasses[0][0]

                    filename = name.replace("/", "_").replace(" ", ".")
                    hasbird = list(
                        filter(lambda canidate: (canidate in name),
                               interesting))

                    filename += ".jpg"
                    # print('writing', filename)

                    if hasbird:
                        camera.capture(
                            filename
                        )  # the twitter client only reads from disk (for now FIXME)

                        now = datetime.datetime.now()
                        deltat = now - lasttime
                        if deltat > maxdelta:
                            lasttime = now
                            if not testing:
                                tweeter.tweet(
                                    filename,
                                    'I just saw a hummingbird! tweet tweet!')
                                print('tweet a bird')
                            else:
                                print('test a bird')
                        else:
                            print('ignore a bird')
예제 #5
0
def responder(geosearchclass, respond, filename):
    if not respond:
        print "No responses sent!"
        return
    with codecs.open(filename, encoding='utf-8', mode='rU') as json_file:
        json_string = json_file.read()
        tweets = json.loads(json_string)
        for tweet in tweets:
            user = tweet[0]
            response_text = geosearchclass.tweet_text + u" @" + user
            id = int(tweet[2])
            users_text = tweet[3]

            print "Please confirm you want to respond to this tweet"
            print user
            print users_text
            print "with this text: "
            print response_text
            response = raw_input("[y for Yes, n for No] :  ")
            if response == 'y':
                # response_text = "Wub a luba dub dub!"
                # id = None
                status = tweeter.tweet(geosearchclass.api, response_text, id)
                print "This tweet was posted: "
                utils.get_simplified_tweet(status)
                
    return
예제 #6
0
def responder(geosearchclass, respond, filename):
    if not respond:
        print "No responses sent!"
        return
    with codecs.open(filename, encoding='utf-8', mode='rU') as json_file:
        json_string = json_file.read()
        tweets = json.loads(json_string)
        for tweet in tweets:
            user = tweet[0]
            response_text = geosearchclass.tweet_text + u" @" + user
            if len(response_text) > 140:
                raise ValueError("Tweet text is > 140 characters. Can't post. \
Shorten the tweet text in the params file")
            id = int(tweet[2])
            users_text = tweet[3]

            print "\n\n\nPlease confirm you want to respond to this tweet"
            print user
            print users_text
            print "with this text: "
            print response_text
            response = raw_input("[y for Yes, anything for No] :  ")
            if response == 'y':
                status = tweeter.tweet(geosearchclass.api, response_text, id)
                print "This tweet was posted: "
                utils.get_simplified_tweet(status)

    return
예제 #7
0
파일: howxisthaty.py 프로젝트: d-baker/bots
def gen():
    adjectives = list(open("resources/adjectives.txt"))
    nouns = list(open("resources/nouns.txt"))

    phrase = ("how {adjective} is that {noun}").format(
        adjective = random.choice(adjectives).strip(),
        noun = random.choice(nouns).strip()
        )

    if random.random() <= 0.2:
        phrase += "!"

    if os.path.exists("resources/tweeted.txt"):
        tweeted = list(open("resources/tweeted.txt", "r").read().split())
        if phrase in tweeted:
            print ("error: already tweeted that one")

    tweet(phrase)
    with open("resources/tweeted.txt", "a") as fp:
        fp.write(phrase + "\n")
예제 #8
0
def wordsTT():
    lista = tweet()
    new_list = []
    new_text = ''
    espaco = ' '

    #me retorna somente as palavras usadas em cada trend
    for text in lista:
        tokens = nltk.word_tokenize(text)
        for p in tokens:
            if p not in stopwords_pt or p not in stopwords_en:
                new_text = new_text + espaco + p

        new_list.append(new_text)
        new_text = ''

    return new_list
예제 #9
0
파일: bot.py 프로젝트: d-baker/bots
import random
from tweeter import tweet

suffixes = ["saurus", "saur", "don", "ilia", "sauriform", "raptor", "ceratops", "saura", "ryx"]
prefixes = []

with open ("resources/dinosaurs.txt") as fp:
    for word in fp.read().split():
        w = word
        for suffix in suffixes:
            if suffix in word:
                w = word.replace(suffix, "")

        prefixes.append(w)


def gen():
    p = random.choice(prefixes)
    s = random.choice(suffixes)
    if p[len(p) - 1] == s[0]:
        s = s[1:]

    return p + s

if __name__ == "__main__":
    #for i in range (0, 10):
    #    print gen()
    tweet(gen())
예제 #10
0
파일: picam.py 프로젝트: petermunch/picam
                        debugim[x,y] = (0, 255, 0) # in debug mode, mark all changed pixel to green
                # Save an image if pixels changed
                if (changedPixels > sensitivity):
                    takePicture = True # will shoot the photo later
                if ((debugMode == False) and (changedPixels > sensitivity)):
                    break  # break the y loop
            if ((debugMode == False) and (changedPixels > sensitivity)):
                break  # break the x loop
        if ((debugMode == False) and (changedPixels > sensitivity)):
            break  # break the z loop
 
    if (debugMode):
        debugimage.save(filepath + "/debug.bmp") # save debug image as bmp
        print "debug.bmp saved, %s changed pixel" % changedPixels
    # else:
    #     print "%s changed pixel" % changedPixels
 
    # Check force capture
    if forceCapture:
        if time.time() - lastCapture > forceCaptureTime:
            takePicture = True
 
    if takePicture:
        lastCapture = time.time()
        saveImage(cameraSettings, saveWidth, saveHeight, saveQuality, diskSpaceToReserve)
        tweet(filename)
 
    # Swap comparison buffers
    image1 = image2
    buffer1 = buffer2
예제 #11
0
파일: seascape.py 프로젝트: d-baker/bots

def generate_sky(time_of_day):
    sky = generate_day_sky() # day is default

    if time_of_day == "night":
        sky = generate_night_sky()

    return sky

def generate_sea():
    water = [(WAVE_CHAR * LINE_LENGTH)] * SEA_LINES
    water = [float_boat(line) for line in water]
    return "\n".join(water)

################################################################################

def generate_seascape():
    time_of_day = random.choice(["night", "day"])

    sky = generate_sky(time_of_day)
    sea = generate_sea()

    seascape = sky + "\n" + sea

    return seascape


if __name__ == "__main__":
    tweet( generate_seascape() )
예제 #12
0
def publish(num):
    '''Publish.'''
    hashtags = tweeter.get_hashtags()
    tweets = get_tweets(int(num), hashtags)
    return jsonify(tweeter.tweet(tweets))
예제 #13
0
 def send_tweet(self):
     message = self.message
     tweeter.tweet(message)
     return redirect(url_for('index'))