Skip to content
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

make it possible to include headers #40

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,12 @@ Since *feeds* is a list you can add additional feeds to watch if you want.
- url: https://example.org/feed/
template: "dot org: {title} {url}"

## Custom Headers

if you want to include own headers you can place `custom_http_headers` in your config:

....
feeds:
- url: https://example.com/feed/
template: "dot com: {title} {url}"
custom_http_headers: 'header1: value1, header2: value2'
20 changes: 15 additions & 5 deletions feediverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def main():
print("using config file", config_file)

if not os.path.isfile(config_file):
setup(config_file)
setup(config_file)

config = read_config(config_file)

Expand All @@ -44,10 +44,20 @@ def main():
)

newest_post = config['updated']

for feed in config['feeds']:

try:
feed['custom_http_headers']
except:
http_headers = ''
else:
http_headers = 'request_headers={' + config['custom_http_headers'] + '}'

if args.verbose:
print(f"fetching {feed['url']} entries since {config['updated']}")
for entry in get_feed(feed['url'], config['updated']):
print("HTTP headers: {http_headers}")
for entry in get_feed(feed['url'], config['updated'], http_headers):
newest_post = max(newest_post, entry['updated'])
if args.verbose:
print(entry)
Expand All @@ -60,8 +70,8 @@ def main():
config['updated'] = newest_post.isoformat()
save_config(config, config_file)

def get_feed(feed_url, last_update):
feed = feedparser.parse(feed_url)
def get_feed(feed_url, last_update, http_headers):
feed = feedparser.parse(feed_url, http_headers)
if last_update:
entries = [e for e in feed.entries
if dateutil.parser.parse(e['updated']) > last_update]
Expand Down Expand Up @@ -144,7 +154,7 @@ def setup(config_file):
access_token = input('access_token: ')
else:
print("Ok, I'll need a few things in order to get your access token")
name = input('app name (e.g. feediverse): ')
name = input('app name (e.g. feediverse): ')
client_id, client_secret = Mastodon.create_app(
api_base_url=url,
client_name=name,
Expand Down