Skip to content

Commit

Permalink
Merge pull request #55 from MartinScharrer/timeline_V2
Browse files Browse the repository at this point in the history
Timeline v2
  • Loading branch information
Katzmann1983 authored Jun 25, 2024
2 parents 52f00d5 + b324b96 commit cf746e4
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 75 deletions.
9 changes: 9 additions & 0 deletions pytr/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,15 @@ async def timeline_detail_order(self, order_id):
async def timeline_detail_savings_plan(self, savings_plan_id):
return await self.subscribe({'type': 'timelineDetail', 'savingsPlanId': savings_plan_id})

async def timeline_transactions(self, after=None):
return await self.subscribe({'type': 'timelineTransactions', 'after': after})

async def timeline_activity_log(self, after=None):
return await self.subscribe({'type': 'timelineActivityLog', 'after': after})

async def timeline_detail_v2(self, timeline_id):
return await self.subscribe({'type': 'timelineDetailV2', 'id': timeline_id})

async def search_tags(self):
return await self.subscribe({'type': 'neonSearchTags'})

Expand Down
34 changes: 23 additions & 11 deletions pytr/dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,19 @@ def load_history(self):
self.log.info('Created history file')

async def dl_loop(self):
await self.tl.get_next_timeline(max_age_timestamp=self.since_timestamp)
await self.tl.get_next_timeline_transactions(max_age_timestamp=self.since_timestamp)

while True:
try:
_subscription_id, subscription, response = await self.tr.recv()
except TradeRepublicError as e:
self.log.fatal(str(e))

if subscription['type'] == 'timeline':
await self.tl.get_next_timeline(response, max_age_timestamp=self.since_timestamp)
elif subscription['type'] == 'timelineDetail':
if subscription['type'] == 'timelineTransactions':
await self.tl.get_next_timeline_transactions(response, max_age_timestamp=self.since_timestamp)
elif subscription['type'] == 'timelineActivityLog':
await self.tl.get_next_timeline_activity_log(response, max_age_timestamp=self.since_timestamp)
elif subscription['type'] == 'timelineDetailV2':
await self.tl.timelineDetail(response, self, max_age_timestamp=self.since_timestamp)
else:
self.log.warning(f"unmatched subscription of type '{subscription['type']}':\n{preview(response)}")
Expand All @@ -86,17 +88,26 @@ def dl_doc(self, doc, titleText, subtitleText, subfolder=None):
send asynchronous request, append future with filepath to self.futures
'''
doc_url = doc['action']['payload']

date = doc['detail']
iso_date = '-'.join(date.split('.')[::-1])
if subtitleText is None:
subtitleText = ''

try:
date = doc['detail']
iso_date = '-'.join(date.split('.')[::-1])
except KeyError:
date = ''
iso_date = ''
doc_id = doc['id']

# extract time from subtitleText
time = re.findall('um (\\d+:\\d+) Uhr', subtitleText)
if time == []:
try:
time = re.findall('um (\\d+:\\d+) Uhr', subtitleText)
if time == []:
time = ''
else:
time = f' {time[0]}'
except TypeError:
time = ''
else:
time = f' {time[0]}'

if subfolder is not None:
directory = self.output_path / subfolder
Expand Down Expand Up @@ -141,6 +152,7 @@ def dl_doc(self, doc, titleText, subtitleText, subfolder=None):
return
else:
filepath = filepath_with_doc_id
doc['local filepath'] = str(filepath)
self.filepaths.append(filepath)

if filepath.is_file() is False:
Expand Down
Loading

0 comments on commit cf746e4

Please sign in to comment.