-
Notifications
You must be signed in to change notification settings - Fork 2
Amend Twitter client #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
c-m-hunt
wants to merge
6
commits into
NathanDeMaria:main
Choose a base branch
from
c-m-hunt:amend-twitter-client
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3a165c3
Add twitter creds file and update ignore
c-m-hunt 8c94ed5
Add logging. Add loop to get down to Slack size
c-m-hunt 71a5369
Rename twitter to twitter_helper to avoid clash. Update twitter to us…
c-m-hunt a1d1720
Update setup and requirements
c-m-hunt f228c09
Update README
c-m-hunt af9ed15
Extract max size
c-m-hunt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,3 +6,7 @@ | |
| # PyCharm | ||
| .idea/ | ||
|
|
||
| build | ||
| dist | ||
|
|
||
| twitter_creds.json | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| from .ffmpeg import mp4_to_gif | ||
| from .twitter import find_mp4 | ||
| from .twitter_helper import find_video |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import twitter | ||
| import json | ||
| import sys | ||
| import os | ||
| from logging import Logger | ||
| import pkg_resources | ||
|
|
||
| def _get_creds(): | ||
| with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'data', 'twitter_creds.json'), 'r') as f: | ||
| creds = json.load(f) | ||
| return creds | ||
|
|
||
|
|
||
| def find_video(tweet_url: str, log: Logger) -> str: | ||
| r""" | ||
| Gets the video URL from the Tweet | ||
|
|
||
| :param tweet_url: URL for a tweet with a video. | ||
| :return: URL of the video itself. | ||
| """ | ||
| try: | ||
| creds = _get_creds() | ||
| api = twitter.Api( | ||
| consumer_key=creds['consumer_key'], | ||
| access_token_key=creds['access_token_key'], | ||
| consumer_secret=creds['consumer_secret'], | ||
| access_token_secret=creds['access_token_secret'] | ||
| ) | ||
| except Exception as e: | ||
| log.error(e) | ||
| raise Exception("There was a problem with your twitter creds") | ||
| tweet_id = tweet_url.strip("/").split("/")[-1] | ||
|
|
||
| status = api.GetStatus(tweet_id) | ||
| media = status.media | ||
|
|
||
| try: | ||
| video = media[0].AsDict() | ||
|
|
||
| saved_variant = None | ||
| # Default to m3u8, then highest quality mp4 | ||
| for variant in video['video_info']['variants']: | ||
| if variant['content_type'] == 'application/x-mpegURL': | ||
| saved_variant = variant | ||
| break | ||
| elif saved_variant == None: | ||
| saved_variant = variant | ||
| elif variant['content_type'] == "video/mp4" and variant['bitrate'] > saved_variant['bitrate']: | ||
| saved_variant = variant | ||
|
|
||
| return saved_variant['url'].split("?")[0] #Remove query string | ||
| except Exception as e: | ||
| raise Exception("There's no video on this Twitter post") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,3 @@ | ||
| cssselect==1.0.3 | ||
| docopt==0.6.2 | ||
| fire==0.1.3 | ||
| lxml==4.1.1 | ||
| requests==2.21.0 | ||
| python-twitter==3.5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "consumer_key": "xxxxx", | ||
| "access_token_key": "xxxxx", | ||
| "consumer_secret": "xxxxx", | ||
| "access_token_secret": "xxxxx" | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to put it in
data/twitter_creds.json. Sound right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. Late change here and forgot to update README
https://github.com/NathanDeMaria/PictureToBurn/pull/15/files#diff-2eeaed663bd0d25b7e608891384b7298R12