APiS-Scraper
PL
Web scraper w Pythonie do pozyskiwania poparcia Polskich partii politycznych!
Oto prosta biblioteka która pobiera strone http://ewybory.eu/sondaze (mam nadzieje że właściciele stronki nie mają nic przeciwko ;), i wyciąga z niej procenty poparcia poszczególnych partii
Możesz je wykorzystać do jakiegoś kreatywnego fajnego projektu :)
Jak korzystać?
- Zainstaluj:
pip3 install -U apis-scraper - Zaimportuj:
import apis_scraper - Użyj funkcji
apis_scraper.scrape(). Zwraca ona słownik, wyglądający tak:
{
'success': True, # Czy się udało, jeśli nie - False
'support' : { # Słownik z % poparcia - liczba z przecinkiem
'pis': 10.0,
'ko': 10.0,
'lewica': 10.0,
'konfederacja': 10.0,
'psl': 10.0,
'polska2050': 10.0
}, # Jeśli coś pójdzie nie tak, wszysktkie poparcia będą -1 a 'success' = False
'growth': { # Czy poparcie rośnie/spada. -1=spada, 0=takie same, 1=rośnie
'pis': 0,
'ko': 0,
'lewica': 0,
'konfederacja': 0,
'psl': 0,
'polska2050': 0
}
}
Przykładowy kod:
import apis_scraper
wyniki = apis_scraper.scrape()
if wyniki['success'] == False:
print('Nie dało rady - nie ma internetu czy coś :/')
exit(-1)
if wyniki['support']['pis'] < wyniki['support']['ko']:
print('Trzeba anulować, bo przegramy...')
Domyślnie, biblioteka zapisuje wyniki w pliku vote-results.json, żeby nie musiała zawsze pobierać strony z internetu - wyniki i tak zmieniają sie co ~tydzień.
Zapisane wyniki wyczerpują się po 24 godzinach.
Jeśli chcesz to zmienić, możesz:
apis_scraper.scrape(
no_cache=True, # Kompletenie wyłącza zapisywanie w pliku - nie polecam
cache_file_name='dupa12.json', # Zmienia nazwe pliku
cache_expire_time=1*60*60
# Zmienia czas (w sekundach) po którym plik sie wyczerpuje,
# i strona jest pobierana na nowo
)
EN
Python web scraper for getting Polish political parties support percentage!
This is a simple library which downloads site http://ewybory.eu/sondaze (I hope that administators don't mind ;) and scrapes support percentage of each party from it
You can then use it for some fun creative project ;)
How to use?
- Install it:
pip3 install -U apis-scraper - Import it:
import apis_scraper - Use function
apis_scraper.scrape(). It returns a dict, which looks like this:
{
'success': True, # If it was succesfull, if not - False
'support' : { # Dict with % of support - in float
'pis': 10.0,
'ko': 10.0,
'lewica': 10.0,
'konfederacja': 10.0,
'psl': 10.0,
'polska2050': 10.0
}, # If something goes wrong, all supports will be -1 and 'success' = False
'growth': { # Whether support is growing or falling. -1=falling, 0=stays same, 1=growing
'pis': 0,
'ko': 0,
'lewica': 0,
'konfederacja': 0,
'psl': 0,
'polska2050': 0
}
}
Example code:
import apis_scraper
wyniki = apis_scraper.scrape()
if wyniki['success'] == False:
print("Can't do - no internet or something :/")
exit(-1)
if wyniki['support']['pis'] < wyniki['support']['ko']:
print('We need to cancel, or we will lose...')
By default, library saves results in vote-results.json file, so it doesn't need to download the site every time - results change ~once a week anyway.
Saved results expire after 24h
If you want to change this, you can:
apis_scraper.scrape(
no_cache=True, # Completley disable cache - not recommended
cache_file_name='dupa12.json', # Change file name
cache_expire_time=1*60*60
# Change time (in seconds) after file expires, and site is downloaded again
)
Metadata
Release files for apis-scraper 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| apis-scraper-1.0.1.tar.gz | 4.7 kB | Without provenance | Details for apis-scraper-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| apis_scraper-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for apis_scraper-1.0.1-py3-none-any.whl |
Total release size: 13.4 kB
Release files / apis-scraper-1.0.1.tar.gz
| Download URL | apis-scraper-1.0.1.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fbd37999c28fe0f2e15887ca08a97181e559d7b1e8d4b0965507bf49c4a02329
|
|
BLAKE2b-256 checksum How to use checksums |
1251fb408ec4ac67d301a4b2facf25c85e1c811fbf55de9f9c24a8212dc2e514
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.2
|
Release files / apis_scraper-1.0.1-py3-none-any.whl
| Download URL | apis_scraper-1.0.1-py3-none-any.whl |
|---|---|
| Size | 8.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3f6a697949bf54c2ca7e25a014ae402461f03fefb89dc70103028370ea182a1a
|
|
BLAKE2b-256 checksum How to use checksums |
b62040880f53c529c2aa5cb36f9fa00ce61c4346860756443eac5dd92bdc0da5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.2
|
Security for apis-scraper 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.