예제 #1
0
def tweet_data(config, parsed_string):
  twitter_credentials = config['twitter']
  twitter_session = Twitter()
  twitter_session.login(twitter_credentials['username'], twitter_credentials['password'])

  num_tweets = len(parsed_string)
  count = 1

  for tweet in parsed_string:
    print("sending tweet {}/{}".format(count, num_tweets))
    twitter_session.tweet(tweet)
    count = count + 1
예제 #2
0
#Main Prog Loop
loops = 0
constant_empty_rgb_val = 0
while (True):
    if (loops < 2):
        if (loops == 0):
            print("Calibrating, please ensure pot is FULL,")
            raw_input("Press ENTER when pot is FULL...")
            constant_empty_rgb_val += getAVGcoffee(4)
        else:
            constant_empty_rgb_val += getAVGcoffee(5)
            constant_empty_rgb_val /= 2
    else:
        print("Checking for coffee... ")
        currentCoffeeLevel = getAVGcoffee(4)
        percentDiff = (abs(constant_empty_rgb_val - currentCoffeeLevel) /
                       float(constant_empty_rgb_val)) * 100.0
        onlineCoffee.updateCoffeeSite(percentDiff < 11)
        print("RGB val of pot is: " + str(currentCoffeeLevel))
        print(
            "There is approximately {}% coffee in the pot".format(percentDiff))
        if (loops % 10 == 0):
            t = Twitter()
            if (currentCoffeeLevel == 100):
                t.tweet(True)
            else:
                t.tweet(False)
        #time.sleep(3)
    loops += 1
예제 #3
0
                                            minSize=(70, 50))
        return houghlines(roi_color, x, y, w, h)


while True:
    percent = 0
    tries = 5
    successes = 0
    votes = 0
    t = Twitter()
    for i in range(tries):
        numPercent = detect()
        if (numPercent > 0 and numPercent < 101):
            percent += numPercent
            successes += 1
    if (successes > 0):
        percent /= tries
    else:
        percent = 0
    print("********* UPDATING **********")
    if percent < 10:
        onlineCoffee.updateCoffeeSite(
            "We've most likely run out of coffee... I blame Kevin")
        t.tweet("We've mos run out of coffee.. stufff")
    else:
        onlineCoffee.updateCoffeeSite("There's plenty of coffee! It's " +
                                      str(int(percent)) + "% full!")
        t.tweet("There's plenty of coffee! It's maybe asdkfljas " +
                str(int(percent)) + "% full!")
    print(percent)
예제 #4
0
components = []
for component in data['components']:
    components.append(Component(statusboardlink, token, component['Cid'], component['Mid'], component['location'], component['name']))

while True:
    try:
        for component in components:
            responseTime = component.getResponseTime()
            if(component.hasComponent()):
                if(responseTime==-1):
                    component.resetSlowAnswer()
                    if(component.tooMuchNoAnswer(10)):
                        if(component.setStatus(4)): #grote storing
                            print(time.strftime('%x %X') + " " + component.getName() + " heeft een grote storing")
                            if(twitter!=False):
                                twitter.tweet(component.getName() + " heeft helaas een grote storing")
                            if(slack!=False):
                                slack.sendMessage(component.getName() + " heeft helaas een grote storing")
                elif(responseTime>800):
                    component.resetNoAnswer()
                    if(component.tooMuchSlowAnswer(10)):
                        if(component.setStatus(2)): #performance issues
                            print(time.strftime('%x %X') + " " + component.getName() + " heeft prestatieproblemen")
                            if(twitter!=False):
                                twitter.tweet(component.getName() + " heeft helaas prestatieproblemen")
                            if(slack!=False):
                                slack.sendMessage(component.getName() + " heeft helaas prestatieproblemen")
                else:
                    component.resetSlowAnswer()
                    component.resetNoAnswer()
                    component.setStatus(1) #operationeel
예제 #5
0
class EigoyurusanBot():
    def __init__(self, lock, logger):
        self.twitter = Twitter(logger)
        translate = Translate(logger)
        self.paper = Paper(logger, translate)
        self.lock = lock
        self.logger = logger

    def make_papers_text(self, titles: list, urls: list, *, prefix=''):
        if len("".join(titles)) == 0: prefix += "\n翻訳に失敗しました."

        length = len("\n".join([prefix] + [f'>{u}\n' for u in urls]))
        title_length = (280 - length) // 8
        trim = lambda title: title if len(
            title) <= title_length else title[:title_length - 2] + '..'
        text = "\n".join([prefix] +
                         [f'>{trim(t)}\n{u}' for u, t in zip(titles, urls)])
        return text

    def auto_follow(self):
        self.twitter.followback()

    def auto_tweet(self):
        '''
        Automatically tweets the content of papers
        searched for in random categories
        '''
        category, ret_list = self.paper.getOutputByRandom()
        urls, titles = zip(*ret_list)

        text = self.make_papers_text(titles, urls, prefix=f'#英許_{category[1]}')
        media_ids = self.twitter.upload_papers('./images/auto/eigoyurusan/')
        self.twitter.tweet(text, media_ids=media_ids)

    def reply(self):
        '''
        Get 200 replies to yourself in a tweet on
        the timeline and tweet an image of the
        resulting translation.
        '''
        timeline = self.twitter.get_mentions_custom()
        if len(timeline) == 0:
            self.logger.info("reply tweets doesn't exist.")
            return

        for status in reversed(timeline):
            self.twitter.try_create_favorite(status.id)
        for status in reversed(timeline):
            self.twitter.follow_if_not(status.author.id)
            screen_name = status.author.screen_name
            prefix = f"@{screen_name} "

            #inpが相手の返信内容
            keywords = status.text.replace('\n', ' ').split(" ")
            keywords = [k for k in keywords if "@" not in k]
            keywords = " ".join(keywords)
            keywords = "".join(
                [c for c in keywords if c not in emoji.UNICODE_EMOJI])
            self.logger.info(f"keywords {keywords} are sent by {screen_name}")

            #Keyword search Module
            ret_list, t_keyword = self.paper.getOutputByKeyword(
                screen_name, keywords)

            if len(ret_list) == 0:
                self.logger.info(f"no retlist, {t_keyword}")
                prefix += f'sorry no result for {t_keyword}'
                self.twitter.tweet(prefix, reply_to=status.id)
                continue

            urls, titles = zip(*ret_list)

            if t_keyword != keywords:
                prefix += f":{t_keyword}" if len(
                    t_keyword) < 40 else f":{t_keyword[:37]}..."
            text = self.make_papers_text(titles, urls, prefix=prefix)
            self.logger.info(text)
            media_ids = self.twitter.upload_papers(
                f'./images/reply/{screen_name}/')
            self.twitter.tweet(text, media_ids=media_ids, reply_to=status.id)
예제 #6
0
        return avg_rgb_val
    
#Main Prog Loop
loops = 0
constant_empty_rgb_val = 0
while(True):
    if(loops < 2):
        if(loops == 0):
            print("Calibrating, please ensure pot is FULL,")
            raw_input("Press ENTER when pot is FULL...")
            constant_empty_rgb_val += getAVGcoffee(4)
        else:
            constant_empty_rgb_val += getAVGcoffee(5)
            constant_empty_rgb_val /= 2
    else:
        print("Checking for coffee... ")
        currentCoffeeLevel = getAVGcoffee(4)
        percentDiff = (abs(constant_empty_rgb_val -currentCoffeeLevel)/float(constant_empty_rgb_val))*100.0
        onlineCoffee.updateCoffeeSite(percentDiff < 11)
        print("RGB val of pot is: " + str(currentCoffeeLevel))
        print("There is approximately {}% coffee in the pot".format(percentDiff))
        if (loops % 10 == 0):
            t = Twitter()
            if (currentCoffeeLevel == 100):
                t.tweet(True)
            else:
                t.tweet(False)   
        #time.sleep(3)
    loops += 1
예제 #7
0
        img = cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
        roi_gray = gray[y:y+h, x:x+w]
        roi_color = img[y:y+h, x:x+w]
        eyes = eye_cascade.detectMultiScale(roi_gray, 1.2, 10, minSize=(70,50))
        return houghlines(roi_color,x,y,w,h)

while True:
    percent = 0
    tries = 5
    successes = 0
    votes = 0
    t = Twitter()
    for i in range(tries):
        numPercent =detect()
        if(numPercent > 0 and numPercent < 101):
            percent += numPercent
            successes += 1
    if(successes>0):
        percent /= tries
    else:
        percent = 0
    print("********* UPDATING **********")
    if percent < 10:
        onlineCoffee.updateCoffeeSite("We've most likely run out of coffee... I blame Kevin")
        t.tweet("We've mos run out of coffee.. stufff")
    else:
        onlineCoffee.updateCoffeeSite("There's plenty of coffee! It's " + str(int(percent)) + "% full!")
        t.tweet("There's plenty of coffee! It's maybe asdkfljas " + str(int(percent)) + "% full!")
    print(percent)