implement title getter for bookmarks
This commit is contained in:
parent
3354021cbd
commit
7376dc4dc9
|
@ -53,14 +53,12 @@ def cli():
|
||||||
dotenv.load_dotenv()
|
dotenv.load_dotenv()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
@click.option("--folder", type=click.Path(dir_okay=True, file_okay=False), required=True)
|
@click.option("--folder", type=click.Path(dir_okay=True, file_okay=False), required=True)
|
||||||
def fetch_link_titles(folder):
|
def fetch_link_titles(folder):
|
||||||
"""Fetch titles for reply and bookmark links"""
|
"""Fetch titles for reply and bookmark links"""
|
||||||
|
|
||||||
for root, _, files in os.walk(folder):
|
for root, _, files in os.walk(folder):
|
||||||
|
|
||||||
for file in files:
|
for file in files:
|
||||||
if file.endswith(".md"):
|
if file.endswith(".md"):
|
||||||
full_path = os.path.join(root, file)
|
full_path = os.path.join(root, file)
|
||||||
|
@ -68,26 +66,44 @@ def fetch_link_titles(folder):
|
||||||
|
|
||||||
print(f"Analysing... {full_path}")
|
print(f"Analysing... {full_path}")
|
||||||
|
|
||||||
reply_data = data.get('in-reply-to')
|
properties_to_check = ['in-reply-to', 'bookmark-of']
|
||||||
|
updated = False
|
||||||
|
|
||||||
if 'twitter.com' in reply_data:
|
for property_name in properties_to_check:
|
||||||
print("Not grabbing title for tweet")
|
|
||||||
continue
|
|
||||||
|
|
||||||
if type(reply_data) == str:
|
property_data = data.get(property_name)
|
||||||
title = get_html_title(reply_data)
|
|
||||||
|
|
||||||
if title is not None:
|
if property_data:
|
||||||
print(f"Found in-reply-to title: '{title}'")
|
if isinstance(property_data, str):
|
||||||
data['in-reply-to'] = {"url": reply_data,
|
if 'twitter.com' in property_data:
|
||||||
"title": str(title)}
|
print(f"Not grabbing title for tweet in {property_name}")
|
||||||
|
continue
|
||||||
|
|
||||||
print(f"Updating in-reply-to data... {full_path}")
|
title = get_html_title(property_data)
|
||||||
|
|
||||||
with open(full_path, 'wb') as f:
|
if title is not None:
|
||||||
frontmatter.dump(data, f)
|
print(f"Found {property_name} title: '{title}'")
|
||||||
|
data[property_name] = {"url": property_data, "title": str(title)}
|
||||||
|
updated = True
|
||||||
|
|
||||||
# parse the response and extract the title
|
elif isinstance(property_data, dict) and 'url' in property_data:
|
||||||
|
|
||||||
|
if 'twitter.com' in property_data['url']:
|
||||||
|
print(f"Not grabbing title for tweet in {property_name}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
if 'title' not in property_data:
|
||||||
|
title = get_html_title(property_data['url'])
|
||||||
|
if title is not None:
|
||||||
|
print(f"Found {property_name} title: '{title}'")
|
||||||
|
property_data['title'] = str(title)
|
||||||
|
data[property_name] = property_data
|
||||||
|
updated = True
|
||||||
|
|
||||||
|
if updated:
|
||||||
|
print(f"Updating data... {full_path}")
|
||||||
|
with open(full_path, 'wb') as f:
|
||||||
|
frontmatter.dump(data, f)
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
|
|
Loading…
Reference in New Issue