Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SACHA txt Downloader
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Georg Petz
SACHA txt Downloader
Commits
55fb76e3
Commit
55fb76e3
authored
4 years ago
by
Georg Petz
Browse files
Options
Downloads
Patches
Plain Diff
update
parent
c744aba2
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitignore
+2
-0
2 additions, 0 deletions
.gitignore
txtDownloader.ipynb
+15
-28
15 additions, 28 deletions
txtDownloader.ipynb
with
17 additions
and
28 deletions
.gitignore
0 → 100644
+
2
−
0
View file @
55fb76e3
venv/
This diff is collapsed.
Click to expand it.
txtDownloader.ipynb
+
15
−
28
View file @
55fb76e3
...
...
@@ -15,50 +15,39 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"e.g.:+Z196807705"
"
Insert a Barcode from the ABO project into the input box,
e.g.:+Z196807705
.
"
]
},
{
"cell_type": "code",
"execution_count":
2
,
"execution_count":
8
,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+Z196807705\n"
"+Z196807705\n",
"URL of the IIIF Manifest: https://iiif.onb.ac.at/presentation/ABO/+Z196807705/manifest/\n"
]
}
],
"source": [
"barcode=input() "
"barcode=input()\n",
"url=\"https://iiif.onb.ac.at/presentation/ABO/\"+barcode+\"/manifest/\"\n",
"print (\"URL of the IIIF Manifest: \" + url)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'https://iiif.onb.ac.at/presentation/ABO/+Z196807705/manifest/'"
]
},
"execution_count": 3,
"cell_type": "markdown",
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"url=\"https://iiif.onb.ac.at/presentation/ABO/\"+barcode+\"/manifest/\"\n",
"url"
"Click on {Barcode}.zip to actually download the zip to your computer."
]
},
{
"cell_type": "code",
"execution_count":
4
,
"execution_count":
11
,
"metadata": {},
"outputs": [
{
...
...
@@ -89,10 +78,10 @@
"<a href='+Z196807705.zip' target='_blank'>+Z196807705.zip</a><br>"
],
"text/plain": [
"
/home/georg/
Projekte
/sacha/
sacha-txt-downloader
/
+Z196807705.zip"
"
C:\\
Projekte
\\
sacha-txt-downloader
\\
+Z196807705.zip"
]
},
"execution_count":
4
,
"execution_count":
11
,
"metadata": {},
"output_type": "execute_result"
}
...
...
@@ -101,15 +90,13 @@
"response = urllib.request.urlopen(url)\n",
"data = json.loads(response.read())\n",
"\n",
"i=0\n",
"zipObj = ZipFile(barcode + \".zip\", \"w\")\n",
"all_txt = open(\"all.txt\",\"wb\")\n",
"\n",
"for page in data[\"sequences\"][0][\"canvases\"]:\n",
" txt_url = page[\"otherContent\"][0][\"resources\"][0][\"resource\"][\"@id\"]\n",
" i=i+1\n",
" print(\"downloading \" + txt_url)\n",
" output_file = str(
i) + \".txt\"
\n",
" output_file = str(
txt_url.split('/')[-1])
\n",
" with urllib.request.urlopen(txt_url) as response, open(output_file, \"wb\") as out_file:\n",
" shutil.copyfileobj(response, out_file)\n",
" zipObj.write(os.path.abspath(output_file),output_file)\n",
...
...
@@ -148,7 +135,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.
8.5
"
"version": "3.
9.0
"
}
},
"nbformat": 4,
...
...
%% Cell type:code id: tags:
```
python
import
urllib.request
,
json
,
shutil
,
os
from
zipfile
import
ZipFile
from
IPython.display
import
FileLink
```
%% Cell type:markdown id: tags:
e.g.:+Z196807705
Insert a Barcode from the ABO project into the input box,
e.g.:+Z196807705
.
%% Cell type:code id: tags:
```
python
barcode
=
input
()
url
=
"
https://iiif.onb.ac.at/presentation/ABO/
"
+
barcode
+
"
/manifest/
"
print
(
"
URL of the IIIF Manifest:
"
+
url
)
```
%% Output
+Z196807705
URL of the IIIF Manifest: https://iiif.onb.ac.at/presentation/ABO/+Z196807705/manifest/
%% Cell type:code id: tags:
```
python
url
=
"
https://iiif.onb.ac.at/presentation/ABO/
"
+
barcode
+
"
/manifest/
"
url
```
%% Output
%% Cell type:markdown id: tags:
'https://iiif.onb.ac.at/presentation/ABO/+Z196807705/manifest/'
Click on {Barcode}.zip to actually download the zip to your computer.
%% Cell type:code id: tags:
```
python
response
=
urllib
.
request
.
urlopen
(
url
)
data
=
json
.
loads
(
response
.
read
())
i
=
0
zipObj
=
ZipFile
(
barcode
+
"
.zip
"
,
"
w
"
)
all_txt
=
open
(
"
all.txt
"
,
"
wb
"
)
for
page
in
data
[
"
sequences
"
][
0
][
"
canvases
"
]:
txt_url
=
page
[
"
otherContent
"
][
0
][
"
resources
"
][
0
][
"
resource
"
][
"
@id
"
]
i
=
i
+
1
print
(
"
downloading
"
+
txt_url
)
output_file
=
str
(
i
)
+
"
.txt
"
output_file
=
str
(
txt_url
.
split
(
'
/
'
)[
-
1
])
with
urllib
.
request
.
urlopen
(
txt_url
)
as
response
,
open
(
output_file
,
"
wb
"
)
as
out_file
:
shutil
.
copyfileobj
(
response
,
out_file
)
zipObj
.
write
(
os
.
path
.
abspath
(
output_file
),
output_file
)
txt_page
=
open
(
output_file
,
"
rb
"
)
shutil
.
copyfileobj
(
txt_page
,
all_txt
)
txt_page
.
close
os
.
remove
(
output_file
)
zipObj
.
write
(
"
all.txt
"
)
all_txt
.
close
()
os
.
remove
(
"
all.txt
"
)
zipObj
.
close
()
FileLink
(
barcode
+
"
.zip
"
)
```
%% Output
downloading https://iiif.onb.ac.at/presentation/ABO/Z196807705/resource/00000001.txt
downloading https://iiif.onb.ac.at/presentation/ABO/Z196807705/resource/00000002.txt
downloading https://iiif.onb.ac.at/presentation/ABO/Z196807705/resource/00000003.txt
downloading https://iiif.onb.ac.at/presentation/ABO/Z196807705/resource/00000004.txt
downloading https://iiif.onb.ac.at/presentation/ABO/Z196807705/resource/00000005.txt
downloading https://iiif.onb.ac.at/presentation/ABO/Z196807705/resource/00000006.txt
downloading https://iiif.onb.ac.at/presentation/ABO/Z196807705/resource/00000007.txt
downloading https://iiif.onb.ac.at/presentation/ABO/Z196807705/resource/00000008.txt
downloading https://iiif.onb.ac.at/presentation/ABO/Z196807705/resource/00000009.txt
downloading https://iiif.onb.ac.at/presentation/ABO/Z196807705/resource/00000010.txt
downloading https://iiif.onb.ac.at/presentation/ABO/Z196807705/resource/00000011.txt
downloading https://iiif.onb.ac.at/presentation/ABO/Z196807705/resource/00000012.txt
downloading https://iiif.onb.ac.at/presentation/ABO/Z196807705/resource/00000013.txt
downloading https://iiif.onb.ac.at/presentation/ABO/Z196807705/resource/00000014.txt
downloading https://iiif.onb.ac.at/presentation/ABO/Z196807705/resource/00000015.txt
downloading https://iiif.onb.ac.at/presentation/ABO/Z196807705/resource/00000016.txt
/home/georg/
Projekte
/sacha/
sacha-txt-downloader
/
+Z196807705.zip
C:\
Projekte
\
sacha-txt-downloader
\
+Z196807705.zip
%% Cell type:code id: tags:
```
python
```
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment