Initial commit.
This commit is contained in:
commit
15c01c51c7
13 changed files with 115 additions and 0 deletions
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
**/__pycache__/**
|
||||||
|
**.pyc
|
||||||
|
Pipfile.lock
|
||||||
|
config.json
|
0
Dockerfile
Normal file
0
Dockerfile
Normal file
15
Pipfile
Normal file
15
Pipfile
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
[[source]]
|
||||||
|
name = "pypi"
|
||||||
|
url = "https://pypi.org/simple"
|
||||||
|
verify_ssl = true
|
||||||
|
|
||||||
|
[dev-packages]
|
||||||
|
autopep8 = "*"
|
||||||
|
pylint = "*"
|
||||||
|
pipfile = "*"
|
||||||
|
|
||||||
|
[packages]
|
||||||
|
pipfile = "*"
|
||||||
|
"mastodon.py" = "*"
|
||||||
|
tweepy = "*"
|
||||||
|
python-twitter = "*"
|
8
README.md
Normal file
8
README.md
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# Twitter Media Tool
|
||||||
|
|
||||||
|
This is a project I'm intending to use to create a bot that will monitor my Twitter account media uploads and archive them to use for later and for backup.
|
||||||
|
|
||||||
|
## Contact
|
||||||
|
|
||||||
|
Twitter
|
||||||
|
[@shadow8t4](https://twitter.com/shadow8t4)
|
0
data/.gitkeep
Normal file
0
data/.gitkeep
Normal file
BIN
data/EWXVFrbU0AE29pL.jpg
Normal file
BIN
data/EWXVFrbU0AE29pL.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 178 KiB |
0
docker-compose.yml
Normal file
0
docker-compose.yml
Normal file
14
lib/archival.py
Normal file
14
lib/archival.py
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
from twitter.twitter_utils import parse_media_file
|
||||||
|
|
||||||
|
def archive_media_status(media_object):
|
||||||
|
try:
|
||||||
|
temp_media_file, filename, size, media_type = parse_media_file(media_object.media_url)
|
||||||
|
with open(f'data/{filename}', 'bw+') as archive_file:
|
||||||
|
archive_file.writelines(temp_media_file.readlines())
|
||||||
|
archive_file.close()
|
||||||
|
temp_media_file.close()
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
exit(1)
|
16
lib/authentication.py
Normal file
16
lib/authentication.py
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
#from tweepy import OAuthHandler, API
|
||||||
|
from twitter import Api
|
||||||
|
|
||||||
|
def authenticate_twitter(config):
|
||||||
|
# auth = OAuthHandler(config['api_key'], config['api_key_secret'])
|
||||||
|
# auth.set_access_token(config['access_token'], config['access_token_secret'])
|
||||||
|
# api = API(auth)
|
||||||
|
twitter_api = Api(
|
||||||
|
consumer_key=config['api_key'],
|
||||||
|
consumer_secret=config['api_key_secret'],
|
||||||
|
access_token_key=config['access_token'],
|
||||||
|
access_token_secret=config['access_token_secret']
|
||||||
|
)
|
||||||
|
return twitter_api
|
0
lib/echo_mastodon.py
Normal file
0
lib/echo_mastodon.py
Normal file
26
lib/setup.py
Normal file
26
lib/setup.py
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
from json import load
|
||||||
|
from sys import argv
|
||||||
|
|
||||||
|
|
||||||
|
def import_from_default_path():
|
||||||
|
try:
|
||||||
|
with open('config.json') as config_file:
|
||||||
|
return load(config_file)
|
||||||
|
config_file.close()
|
||||||
|
except Exception as e:
|
||||||
|
print("Couldn't find the config file.")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def import_config_file():
|
||||||
|
if(len(argv) > 1):
|
||||||
|
try:
|
||||||
|
with open(argv[1]) as config_file:
|
||||||
|
return load(config_file)
|
||||||
|
config_file.close()
|
||||||
|
except:
|
||||||
|
return import_from_default_path()
|
||||||
|
else:
|
||||||
|
return import_from_default_path()
|
7
template_config.json
Normal file
7
template_config.json
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"authenticated_user":"",
|
||||||
|
"api_key":"",
|
||||||
|
"api_key_secret":"",
|
||||||
|
"access_token":"",
|
||||||
|
"access_token_secret":""
|
||||||
|
}
|
23
twitter_media_tool.py
Normal file
23
twitter_media_tool.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
# encoding: UTF-8
|
||||||
|
|
||||||
|
#from tweepy import OAuthHandler, API
|
||||||
|
from time import sleep
|
||||||
|
from lib.setup import import_config_file
|
||||||
|
from lib.authentication import authenticate_twitter
|
||||||
|
from lib.archival import archive_media_status
|
||||||
|
|
||||||
|
def main():
|
||||||
|
config = import_config_file()
|
||||||
|
twitter_api = authenticate_twitter(config)
|
||||||
|
authenticated_user = twitter_api.GetUser(screen_name=config['authenticated_user'])
|
||||||
|
try:
|
||||||
|
status_media_list = authenticated_user.status.media
|
||||||
|
for media_file in status_media_list:
|
||||||
|
archive_media_status(media_file)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
|
if(__name__ == '__main__'):
|
||||||
|
main()
|
Reference in a new issue