- commit
- bd712bc63522d5e2d0e70befce8f9a55b0ac55be
- parent
- 2d7540d3e33460969c8cd1a92fae88a0c03eb27f
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2024-06-28 06:45
use f-strings
Diffstat
M | neddit.py | 28 | ++++++++++++++-------------- |
1 files changed, 14 insertions, 14 deletions
diff --git a/neddit.py b/neddit.py
@@ -34,27 +34,27 @@ def relative_datetime(value): 34 34 dt = datetime.fromtimestamp(value) 35 35 delta = datetime.now() - dt 36 36 if delta.days > 365:37 -1 return '%i years ago' % (delta.days // 365)-1 37 return f'{delta.days // 365} years ago' 38 38 elif delta.days > 0:39 -1 return '%i days ago' % delta.days-1 39 return f'{delta.days} days ago' 40 40 elif delta.seconds > 3600:41 -1 return '%i hours ago' % (delta.seconds // 3600)-1 41 return f'{delta.seconds // 3600} hours ago' 42 42 elif delta.seconds > 60:43 -1 return '%i minutes ago' % (delta.seconds // 60)-1 43 return f'{delta.seconds // 60} minutes ago' 44 44 else:45 -1 return '%i seconds ago' % delta.seconds-1 45 return f'{delta.seconds} seconds ago' 46 46 env.filters['dt'] = relative_datetime 47 47 48 48 49 49 def format_number(value):50 -1 if value > 100000000:51 -1 return '%im' % (value // 1000000)52 -1 elif value > 1000000:53 -1 return '%.1fm' % (value / 1000000)54 -1 if value > 100000:55 -1 return '%ik' % (value // 1000)-1 50 if value > 100_000_000: -1 51 return f'{value // 1_000_000}m' -1 52 elif value > 1_000_000: -1 53 return f'{value / 1_000_000:.1f}m' -1 54 if value > 100_000: -1 55 return f'{value // 1000}k' 56 56 elif value > 1000:57 -1 return '%.1fk' % (value / 1000)-1 57 return f'{value / 1000:.1f}k' 58 58 else: 59 59 return str(value) 60 60 env.filters['k'] = format_number @@ -89,7 +89,7 @@ async def fetch(url, **params): 89 89 90 90 @async_cache() 91 91 async def fetch_subreddit(name):92 -1 return await fetch('https://www.reddit.com/r/%s/about.json' % name)-1 92 return await fetch(f'https://www.reddit.com/r/{name}/about.json') 93 93 94 94 95 95 async def favicon(request): @@ -109,7 +109,7 @@ async def generic(request): 109 109 subreddit = path.split('/')[1] 110 110 context['subreddit'] = await fetch_subreddit(subreddit) 111 111112 -1 a = await fetch('https://www.reddit.com/%s/.json' % path, **request.query)-1 112 a = await fetch(f'https://www.reddit.com/{path}/.json', **request.query) 113 113 if isinstance(a, list): 114 114 tpl = env.get_template('comments.html') 115 115 context['post'] = a[0]['data']['children'][0]