gemini.git

going-flying.com gemini git repository

summary

tree

log

refs

9bd316a1dd9757ce0f15b400acff2ac3e34e1f09 - Matthew Ernisse - 1720621942

tweak thoughts-to-gemini

view tree

view raw

diff --git a/files/thoughts-to-gemini.py b/files/thoughts-to-gemini.py
index 4433c09..e572851 100755
--- a/files/thoughts-to-gemini.py
+++ b/files/thoughts-to-gemini.py
@@ -378,14 +378,19 @@ class SuperNum(object):
 
 class ThoughtApi(object):
 	''' Provide an interface to my Thoughts. '''
+	_ua = 'thought-to-gemini/1.0 (+matt@going-flying.com)'
+	_url = 'https://vociferate.azurewebsites.net/api/thoughts'
 	def __init__(self, since=0):
 		self.since = since
 
 	@property
 	def newest(self):
 		''' Return the ID of the newest thought. '''
-		_t = self._get(1, before=int(time.time()))[0]
-		return _t['id']
+		headers = {'User-Agent': self._ua}
+		resp = requests.get(f'{self._url}/latest', headers=headers)
+		resp.raise_for_status()
+
+		return resp.json()
 
 	@property
 	def oldest(self):
@@ -406,7 +411,7 @@ class ThoughtApi(object):
 				yield thought
 
 	def _get(self, count=25, before=None, since=None):
-		headers = {'User-Agent': 'thought-to-gemini/1.0'}
+		headers = {'User-Agent': self._ua}
 		params = {'count': count, 'raw': True}
 
 		if before is not None:
@@ -415,12 +420,7 @@ class ThoughtApi(object):
 		if since is not None:
 			params['since'] = since
 
-		resp = requests.get(
-			'https://vociferate.azurewebsites.net/api/thoughts',
-			headers=headers,
-			params=params
-		)
-
+		resp = requests.get(self._url, headers=headers, params=params)
 		resp.raise_for_status()
 		thoughts = resp.json()
 		thoughts.sort(key=lambda k: k['id'])