Example #1
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
Example #2
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
Example #3
0
def verify(geosearchclass, filename):
    q = Queue.Queue()
    global keep_scanning
    keep_scanning = True
    thread = threading.Thread(target=scan, args=(geosearchclass, q))
    thread.daemon = True
    thread.start()
    respond = False
    with codecs.open(filename, encoding='utf-8', mode='a') as json_file:
        json_file.seek(0)
        json_file.truncate()

        print """\n\n\tThis program will present a series of tweets and ask for you to
        verify if they should be responded to. If so, they will be saved
        to the JSON file. When you quit scanning, the public tweets will
        be sent out.\n"""

        print """Would you like to send tweet responses at the end of this verification
        session?"""
        response = ""
        while response != 'y' and response != 'n':
            response = raw_input("[y for Yes, n for No] :  ")
            print response
        if response == 'y':
            respond = True
        elif response == 'n':
            respond = False

        first = True
        while True:
            if q.empty():
                time.sleep(5)
                continue
            status = q.get()
            print "\n\nVerify if this tweet is what you want:"
            simplified_tweet = utils.get_simplified_tweet(status)
            response = ""
            while response != 'y' and response != 'n' and response != 'q':
                response = raw_input("[y for Yes, n for No, q for Quit] :  ")
            if response == 'y':
                j = json.dumps(simplified_tweet, indent=1)
                if first:
                    json_file.write('[\n')
                    json_file.write(j)
                    first = False
                    continue
                json_file.write(',\n')
                json_file.write(j)
            elif response == 'n':
                continue
            elif response == 'q':
                keep_scanning = False
                thread.join()
                json_file.write('\n]')
                break
    responder(geosearchclass, respond, filename)
    return
Example #4
0
def verify(geosearchclass, filename):
    q = Queue.Queue()
    global keep_scanning
    keep_scanning = True
    thread = threading.Thread(target=scan, args=(geosearchclass, q))
    thread.daemon = True
    thread.start()
    respond = False
    with codecs.open(filename, encoding='utf-8', mode='a') as json_file:
        json_file.seek(0)
        json_file.truncate()

        print """\n\n\tThis program will present a series of tweets and ask for you to
        verify if they should be responded to. If so, they will be saved
        to the JSON file. When you quit scanning, the public tweets will
        be sent out.\n"""

        print """Would you like to send tweet responses at the end of this verification
        session?"""
        response = ""
        while response != 'y' and response != 'n':
            response = raw_input("[y for Yes, n for No] :  ")
            print response
        if response == 'y':
            respond = True
        elif response == 'n':
            respond = False

        first = True
        while True:
            if q.empty():
                time.sleep(5)
                continue
            status = q.get()
            print "\n\nVerify if this tweet is what you want:"
            simplified_tweet = utils.get_simplified_tweet(status)
            response = ""
            while response != 'y' and response != 'n' and response != 'q':
                response = raw_input("[y for Yes, n for No, q for Quit] :  ")
            if response == 'y':
                j = json.dumps(simplified_tweet, indent=1)
                if first:
                    json_file.write('[\n')
                    json_file.write(j)
                    first = False
                    continue
                json_file.write(',\n')
                json_file.write(j)
            elif response == 'n':
                continue
            elif response == 'q':
                keep_scanning = False
                thread.join()
                json_file.write('\n]')
                break
    responder(geosearchclass, respond, filename)
    return
Example #5
0
    def on_status(self, status):
        text = status.text
        if self.search_terms:
            if not self.has_all_search_terms(text):
                return True

        self.queue.put(status)
        # sj = status._json
        sj = utils.get_simplified_tweet(status)
        # filter_lev = status.filter_level
        # print filter_lev
        j = json.dumps(sj, indent=1)
        self.json_file.write(j)
        return True
Example #6
0
 def on_status(self, status):
     text = status.text
     if self.search_terms:
         if not self.has_all_search_terms(text):
             return True
 
     self.queue.put(status)
     # sj = status._json
     sj = utils.get_simplified_tweet(status)
     # filter_lev = status.filter_level
     # print filter_lev
     j = json.dumps(sj, indent=1)
     self.json_file.write(j)
     return True