Skip to content

Commit

Permalink
added --warnings fixes #62 fixes #55
Browse files Browse the repository at this point in the history
  • Loading branch information
edsu committed Nov 9, 2015
1 parent 8885058 commit 3834454
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions twarc.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def main():
help="Config file containing Twitter keys and secrets")
parser.add_argument('-p', '--profile', default='main',
help="Name of a profile in your configuration file")
parser.add_argument('-w', '--warnings', action='store_true',
help="Include warning messages in output")

args = parser.parse_args()

logging.basicConfig(
Expand Down Expand Up @@ -110,10 +113,21 @@ def main():

# iterate through the tweets and write them to stdout
for tweet in tweets:
if "id_str" in tweet:
logging.info("archived %s", tweet["id_str"])

# include warnings in output only if they asked for it
if 'id_str' in tweet or args.warnings:
print(json.dumps(tweet))

# add some info to the log
if "id_str" in tweet:
logging.info("archived https://twitter.com/%s/status/%s", tweet['user']['screen_name'], tweet["id_str"])
elif 'limit' in tweet:
logging.warn("%s tweets undelivered", tweet["limit"]["track"])
elif 'warning' in tweet:
logging.warn(tweet['warning']['message'])
else:
logging.warn(json.dumps(tweet))


def load_config(filename, profile):
if not os.path.isfile(filename):
Expand Down Expand Up @@ -274,7 +288,7 @@ def stream(self, track):
the livestream of tweets happening right now.
"""
url = 'https://stream.twitter.com/1.1/statuses/filter.json'
params = {"track": track}
params = {"track": track, "stall_warning": True}
headers = {'accept-encoding': 'deflate, gzip'}
errors = 0
while True:
Expand Down

0 comments on commit 3834454

Please sign in to comment.