Skip to content

Commit

Permalink
resolved some merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
edsu committed May 22, 2024
2 parents d763097 + dd5e142 commit 84f1365
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions feediverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import argparse
import dateutil
import feedparser
import random
import time
import requests

from bs4 import BeautifulSoup
Expand All @@ -24,6 +26,8 @@ def main():
parser.add_argument("-c", "--config",
help="config file to use",
default=os.path.expanduser(DEFAULT_CONFIG_FILE))
parser.add_argument("-d", "--delay", action="store_true",
help="delay randomly from 10 to 30 seconds between each post")

args = parser.parse_args()
config_file = args.config
Expand Down Expand Up @@ -51,19 +55,28 @@ def main():
newest_post = max(newest_post, entry['updated'])
if args.verbose:
print(entry)

if args.dry_run:
print("trial run, not tooting ", entry["title"][:50])
continue

image_medias = []
if feed['include_images'] and entry['images']:
for image in entry['images'][:4]:
try:
image_response = requests.get(image)
image_medias.append(masto.media_post(image_response.content, mime_type=image_response.headers['Content-Type']))
except:
print('There was an error uploading a file')
masto.status_post(feed['template'].format(**entry)[:499], media_ids=image_medias)
# TODO: handle image fetch and upload exceptions
image_response = requests.get(image)
image_medias.append(masto.media_post(image_response.content, mime_type=image_response.headers['Content-Type']))

if not args.dry_run:
masto.status_post(
feed['template'].format(**entry)[:499],
media_ids=image_medias
)

if args.delay:
delay = random.randrange(10,30)
print("Delaying..." + str(delay) + " seconds...")
time.sleep(delay)

if not args.dry_run:
config['updated'] = newest_post.isoformat()
Expand Down

0 comments on commit 84f1365

Please sign in to comment.