Created
December 26, 2016 16:12
-
-
Save tehPlayer/3ea8ccf7546e23435d7f4389cedc1f3d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Skrypt pozwala na pobieranie z napiprojekt.pl gdy nie posiadamy aplikacji. | |
ID z URL z wynikow wyszukiwania podajemy jako argument do skryptu. Np. | |
$ python napiprojekt.py e79975aa41dfecf52b81ac8231f4abde > napisy.txt | |
Wymagania: | |
* Python 3.X | |
* pip3: requests | |
* pip3: pylzma | |
Testowane na OS X 10.12 | |
Oryginalny kod (dla Python 2): https://gist.github.com/avalanchy/a9216efee614bb2962b2 | |
""" | |
from io import BytesIO | |
import base64 | |
import sys | |
import xml.etree.ElementTree as ET | |
from py7zlib import Archive7z | |
import requests | |
response = requests.post( | |
url='http://www.napiprojekt.pl/api/api-napiprojekt3.php', | |
data=dict( | |
downloaded_subtitles_id=sys.argv[1], | |
downloaded_subtitles_lang='PL', | |
client='NapiProjekt', | |
mode=17, | |
) | |
) | |
parser = ET.XML(response.content) | |
content = parser.find('subtitles').find('content').text | |
decoded = base64.b64decode(content) | |
file_like = BytesIO(decoded) | |
archive = Archive7z(file_like, password='iBlm8NTigvru0Jr0') | |
member = archive.getmember(0) | |
print(member.read().decode('cp1250')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment