thesaurus's People
thesaurus's Issues
API dla Goldman Sachs TFI
Cześć,
Aby pobrać dane dla TFI z Goldman Sachs można skorzystać z dwóch API, aby uniknąć przetwarzania plików HTML i mieć dostęp do danych archiwalnych równiez:
- Analizy.pl: Dostępne jest nie publiczne API, które można znaleźć przez devtools:
https://www.analizy.pl/api/quotation/fio/ING87
- Export CSV z goldman sachs: Można wykorzystać eksport do pliku CSV, który jest dostępny na stronie:
Ja osobiście korzystam z ekspirtu . Na początku pobierałem dane e za pomocą CURL:
curl 'https://www.gstfi.pl/?action=quotes.getQuotesCsv&startDate=2023-03-28&endDate=2024-03-28&fundIds=1500088&unitCategoryIds=1' \
-H 'Accept: */*' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36'
A teraz mam skrypt w Python, który możę cie zainspirować:
import pandas as pd
import requests
FUND_UNIT_URL = 'https://www.gstfi.pl/fundusze-inwestycyjne/fundusze-emerytura-ppk/goldman-sachs-emerytura-2055'
FUND_UNIT_ID_REGEXP = re.compile(r'data-fund-id="(\d+)"')
RATE_CSV_URL = 'https://www.gstfi.pl/'
def fetch_gstfi_rates():
func_unit_url = FUND_UNIT_URL
fund_unit_id = get_func_unit_id(func_unit_url)
start_date = datetime.datetime(2023, 3, 28)
end_date = datetime.datetime(2024, 3, 28)
df = fetch_fund_rates(start_date, end_date, fund_unit_id)
return df
def fetch_fund_rates(start_date, end_date, fund_unit_id):
LOG.debug("Fetching fund rates: fund_unit_id=%s", fund_unit_id)
rate_response = requests.get(RATE_CSV_URL, params={
'action': 'quotes.getQuotesCsv',
'startDate': start_date.strftime('%Y-%m-%d'),
'endDate': end_date.strftime('%Y-%m-%d'),
'fundIds': fund_unit_id,
'unitCategoryIds': 1
})
rate_response.raise_for_status()
df = pd.read_csv(StringIO(rate_response.text))
return df
def get_func_unit_id(func_unit_url):
LOG.debug("Getting fund unit ID: func_unit_url=%s", func_unit_url)
response = requests.get(func_unit_url)
response.raise_for_status()
text_content = response.text
fund_unit_id_match = re.search(FUND_UNIT_ID_REGEXP, text_content)
if not fund_unit_id_match:
raise ValueError("Fund unit ID not found")
fund_unit_id = fund_unit_id_match.group(1)
return fund_unit_id
Poprosiłem ChatGPT o przepisanie na Google AppScript i dostałem taką odpowiedź:
Rewriting the provided Python code into Google Apps Script (GAS) involves a few steps and changes due to the different runtime environments and available libraries. GAS doesn't have a direct equivalent of Python's
pandas
orrequests
libraries, but you can achieve similar functionalities using Google Sheets for data manipulation and theUrlFetchApp
class for HTTP requests.Here's how the Python script can be translated into Google Apps Script:
// Global variables const FUND_UNIT_URL = 'https://www.gstfi.pl/fundusze-inwestycyjne/fundusze-emerytura-ppk/goldman-sachs-emerytura-2055'; const RATE_CSV_URL = 'https://www.gstfi.pl/'; function fetchGstfiRates() { const fundUnitId = getFundUnitId(FUND_UNIT_URL); const startDate = new Date(2023, 2, 28); // Month is 0-indexed const endDate = new Date(2024, 2, 28); // Month is 0-indexed const data = fetchFundRates(startDate, endDate, fundUnitId); // Assuming you want to log or use the data here, for example, log to console. console.log(data); } function fetchFundRates(startDate, endDate, fundUnitId) { const formattedStartDate = Utilities.formatDate(startDate, Session.getScriptTimeZone(), 'yyyy-MM-dd'); const formattedEndDate = Utilities.formatDate(endDate, Session.getScriptTimeZone(), 'yyyy-MM-dd'); const params = { 'action': 'quotes.getQuotesCsv', 'startDate': formattedStartDate, 'endDate': formattedEndDate, 'fundIds': fundUnitId, 'unitCategoryIds': 1 }; const queryString = Object.keys(params).map(key => `${key}=${encodeURIComponent(params[key])}`).join('&'); const response = UrlFetchApp.fetch(`${RATE_CSV_URL}?${queryString}`); // Assuming CSV data is returned and you want to convert it to a 2D array const csvData = Utilities.parseCsv(response.getContentText()); return csvData; } function getFundUnitId(funcUnitUrl) { const response = UrlFetchApp.fetch(funcUnitUrl); const textContent = response.getContentText(); const fundUnitIdRegexp = /data-fund-id="(\d+)"/; const fundUnitIdMatch = textContent.match(fundUnitIdRegexp); if (!fundUnitIdMatch) { throw new Error("Fund unit ID not found"); } const fundUnitId = fundUnitIdMatch[1]; return fundUnitId; }Key Differences and Adjustments:
- Date handling: JavaScript and GAS use 0-indexed months, so the month numbers are adjusted accordingly.
- HTTP requests: GAS uses
UrlFetchApp
for making HTTP requests.- Regular expressions: The syntax remains the same, but GAS uses JavaScript's
match
method.- Data processing: Instead of
pandas
, this example directly manipulates the CSV data. If you need to work extensively with the data, consider using Google Sheets as a database or for further processing.- Logging and output: The example uses
console.log
for logging, but you might want to replace this with appropriate GAS functionalities, such as appending to a Google Sheet.- Error handling: GAS throws errors with
throw new Error("message")
.This script provides a foundation for fetching and processing data in Google Apps Script, mirroring the Python script's functionality within the GAS environment and its capabilities.
Mam nadzieje, że to komuś pomoże.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.