Skip to content

Commit

Permalink
Media command
Browse files Browse the repository at this point in the history
  • Loading branch information
dimazest committed Dec 13, 2018
1 parent d7238a1 commit f06e7e6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
5 changes: 3 additions & 2 deletions CHANGES.rst
@@ -1,8 +1,8 @@
Changes
=======

1.5.0 (in development)
----------------------
1.5.0
-----

* Python 2 is not supported anymore.
* Use the ``full_text`` field to retrieve tweet's text, fall back to ``text`` if
Expand All @@ -16,6 +16,7 @@ Changes
* The ``Tweet.bounding_box`` property is introduced, it is always a polygon.
* The ``--filters`` option for ``filter`` to define what filters are used.
* Refactored communication with Twitter and internal stream handling.
* New ``media`` command.

1.3.0
-----
Expand Down
2 changes: 2 additions & 0 deletions README.rst
Expand Up @@ -3,3 +3,5 @@ Poultry

:documentation: http://poultry.readthedocs.org
:homepage: https://github.com/dimazest/poultry

Poultry is a tweet collection manager.
27 changes: 26 additions & 1 deletion poultry/consumers.py
Expand Up @@ -4,7 +4,7 @@
import logging
import sys
import time
import json
import csv

try:
from Queue import Full
Expand Down Expand Up @@ -417,3 +417,28 @@ def extract_retweets(target):
target.send(retweeted_status)

target.send(raw_tweet)


@consumer
def print_media(output=None):
"""Print media items."""
if output is None:
output = sys.stdout

field_names = 'tweet_id', 'index', 'media_id', 'type', 'media_url'
writer = csv.DictWriter(output, fieldnames=field_names)

while True:
tweet = yield
media = tweet.parsed.get('extended_entities', {}).get('media', [])

for i, m in enumerate(media):
writer.writerow(
{
'tweet_id': tweet.id,
'index': i,
'media_id': m['id'],
'type': m['type'],
'media_url': m['media_url'],
}
)
10 changes: 10 additions & 0 deletions poultry/main.py
Expand Up @@ -104,3 +104,13 @@ def timeline(producer, window=('w', '%Y-%m-%d-%H', '')):
),
),
)


@command()
def media(producer, output):
"""Retrieve media urls."""
producer(
consumers.to_tweet(
consumers.print_media(output=output)
)
)

0 comments on commit f06e7e6

Please sign in to comment.