Skip to content
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# this project
login.py

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
52 changes: 52 additions & 0 deletions start.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

import json

import login

from wikifolio import Wikifolio


wikifolioID = "wf00gk0001"

wf = Wikifolio(login.login_mail, login.login_pw, wikifolioID)


print(wf.performance_since_emission)
print(wf.performance_ever)

print(wf.symbol)
print(wf.description)
print(wf.trader)
print(wf.creation_date)

print(wf.get_price_information())

wf.get_tags()

wf.get_content().underlyings


## Trades

trades = wf.get_trade_history()

for a in trades:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace a with a better name. Maybe for trade in trades:

a.name
a.isin
a.link
a.orderType
a.executionPrice
a.executionDate
a.performance
a.weightage
print('---')


## Portfolio

portf = wf.get_portfolio()

print(json.dumps(portf, indent = 2))

print(json.dumps(portf['groups'][1], indent = 2))

32 changes: 27 additions & 5 deletions wikifolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Wikifolio:
rawData = None
twoFA_key = None

def __init__(self, username: str, password: str, wikifolio_name: str, twoFA_key = None) -> None:
def __init__(self, username: str, password: str, wikifolio_name: str, twoFA_key = None, postprocessRawData: typing.Optional[bool] = True) -> None:
params = {
"email": username,
"password": password,
Expand All @@ -37,17 +37,20 @@ def __init__(self, username: str, password: str, wikifolio_name: str, twoFA_key
r.raise_for_status()
self.cookie = r.cookies
self.name = wikifolio_name
self._get_wikifolio_id(wikifolio_name)
self._get_wikifolio_id(wikifolio_name, postprocessRawData)
self.twoFA_key = twoFA_key

def _get_wikifolio_id(self, name: str) -> None:
def _get_wikifolio_id(self, name: str, postprocessRawData: typing.Optional[bool] = True) -> None:
r = requests.get(
"https://www.wikifolio.com/de/de/w/{}".format(name),
cookies=self.cookie,
)
r.raise_for_status()
html = etree.fromstring(r.text)
result = json.loads(html.xpath('//*[@id="__NEXT_DATA__"]/text()')[0])
rawData = r.text
if postprocessRawData:
rawData = rawData.replace('& ', '')
html_parsed = etree.fromstring(rawData)
result = json.loads(html_parsed.xpath('//*[@id="__NEXT_DATA__"]/text()')[0])
self.wikifolio_id = result["props"]["pageProps"]["data"]["wikifolio"]["id"]
self.rawData = result

Expand Down Expand Up @@ -772,3 +775,22 @@ def remove_order(self, order_uuid: str):
r.raise_for_status()
raw_json = r.json()
return raw_json


def get_portfolio(self):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please wrap the output in a class so you know what to expect (similar to 325ea78)

header = {
"accept": "application/json",
}
params = {
"country": "de",
"language": "de",
}
r = requests.get(
"https://www.wikifolio.com/api/wikifolio/{}/portfolio".format(self.name),
params=params,
headers=header,
cookies=self.cookie,
)
r.raise_for_status()
raw_json = r.json()
return raw_json