worm-library 1.2.2__tar.gz → 1.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: worm_library
3
- Version: 1.2.2
3
+ Version: 1.3.0
4
4
  Summary: Download WORM Portal tutorial notebooks and files
5
5
  Author-email: Grayson Boyer <gmboyer@asu.edu>
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "worm_library"
7
- version = "1.2.2"
7
+ version = "1.3.0"
8
8
  description = "Download WORM Portal tutorial notebooks and files"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -0,0 +1,6 @@
1
+ from .downloader import get_worm_tour, get_introduction_demo
2
+ from .downloader import get_reaction_properties_demo, get_univariant_curve_demo
3
+ from .downloader import get_intro_aqueous_speciation_demo, get_multi_aqueous_speciation_demo, get_charge_balance_demo, get_heterogeneous_equilibrium_demo, get_heterogeneous_equilibrium_gas_demo, get_alter_suppress_demo, get_custom_data0_demo, get_EQ3_demo, get_EQ6_demo, get_intro_mass_transfer_demo, get_mass_transfer_feature_demo, get_mixing_demo, get_speciation_datasets_demo, get_energy_supply_demo
4
+ from .downloader import get_intro_aqorg_demo, get_aqorg_feature_demo, get_propfit_demo, get_complicator_demo, get_estimate_HKF_demo
5
+ from .downloader import get_workshop_demo, delete_all_demos, get_library_notebook
6
+ from .downloader import get_Weeks_2025_demo, get_Trinh_2026_demo, get_whats_in_water_demo
@@ -0,0 +1,227 @@
1
+ from urllib.request import urlopen, urlretrieve
2
+ from pathlib import Path
3
+ import shutil
4
+ from bs4 import BeautifulSoup as bs
5
+ import requests
6
+ import os
7
+ from glob import glob
8
+ from shutil import rmtree
9
+ import json
10
+ import re
11
+
12
+ def get_WORM_demo(demo_name, URL):
13
+
14
+ # check to see if this notebook is being run inside of the read-only WORM Library folder
15
+ cwd = os.getcwd()
16
+
17
+ # main and raw URL prefixes for the WORM library
18
+ URL_main_prefix = 'https://github.com/worm-portal/WORM-Library/tree/master/'
19
+ URL_raw_prefix = 'https://raw.githubusercontent.com/worm-portal/WORM-Library/master/'
20
+
21
+ # delete demo folder if it exists
22
+ dirpath = Path(demo_name)
23
+ if dirpath.exists() and dirpath.is_dir():
24
+ shutil.rmtree(dirpath)
25
+
26
+ # create a fresh demo folder
27
+ dirpath.mkdir()
28
+
29
+ res = requests.get(URL_main_prefix+URL)
30
+ soup = bs(res.text, 'lxml')
31
+ # repo_files = soup.find_all('a', class_="js-navigation-open")
32
+
33
+ #gitstr = str(soup.find_all('p')[0])
34
+
35
+ try:
36
+ try:
37
+ gitstr = str([s for s in soup.find_all('script') if "payload" in str(s)][0])
38
+ gitstr = gitstr.split(">")[1].split("<")[0]
39
+ repo_files = [d["path"].split(URL+"/")[1] for d in json.loads(gitstr)["payload"]["codeViewTreeRoute"]["tree"]["items"]]
40
+ except:
41
+ gitstr = str([s for s in soup.find_all('script') if "payload" in str(s)][1])
42
+ gitstr = gitstr.split(">")[1].split("<")[0]
43
+ repo_files = [d["path"].split(URL+"/")[1] for d in json.loads(gitstr)["payload"]["codeViewTreeRoute"]["tree"]["items"]]
44
+
45
+ # correct for ampersand in file names
46
+ # e.g., S&amp;C10vents.csv becomes S&C10vents.csv
47
+ repo_files = [re.sub("&amp;", "&", f) for f in repo_files]
48
+ except:
49
+ raise Exception("The WORM Library is currently experiencing difficulty connecting to GitHub where demos are "
50
+ "hosted. Please inform Grayson Boyer gmboyer@asu.edu")
51
+
52
+ files = []
53
+ for i in repo_files:
54
+ if ('.csv' in i or '.ipynb' in i or '.3i' in i or '.6i' in i or '.cmp' in i or '.speciation' in i) and '.ipynb_checkpoints' not in i:
55
+ files.append(i)
56
+
57
+ for file in files:
58
+ if '.speciation' not in file and '.3i' not in file and '.6i' not in file and '.cmp' not in file:
59
+ # Download from URL and decode as UTF-8 text.
60
+ with urlopen(URL_raw_prefix+URL+"/"+file) as webpage:
61
+ content = webpage.read().decode()
62
+
63
+ # Save to file.
64
+ with open(demo_name+"/"+file, 'w', encoding='utf-8') as output:
65
+ output.write(content)
66
+ else:
67
+ urlretrieve(URL_raw_prefix+URL+"/"+file, demo_name+"/"+file)
68
+
69
+ print(demo_name+" is ready.")
70
+
71
+
72
+ def get_worm_tour():
73
+ demo_name = "Demo-0-WORM-Tour"
74
+ URL = "WORM-Tour"
75
+ get_WORM_demo(demo_name, URL)
76
+
77
+ def get_introduction_demo():
78
+ demo_name = "Demo-1-Introduction"
79
+ URL = "1-Introduction"
80
+ get_WORM_demo(demo_name, URL)
81
+
82
+ def get_reaction_properties_demo():
83
+ demo_name = "Demo-2-(1-2-3)-Reaction-Properties"
84
+ URL = "2-Reaction-Properties"
85
+ get_WORM_demo(demo_name, URL)
86
+
87
+ def get_univariant_curve_demo():
88
+ demo_name = "Demo-2-4-Geothermometry-Univariant"
89
+ URL = "2-Reaction-Properties/4-Univariant-Curves"
90
+ get_WORM_demo(demo_name, URL)
91
+
92
+ def get_intro_aqueous_speciation_demo():
93
+ demo_name = "Demo-3-1-Intro-Aqueous_Speciation"
94
+ URL = "3-Aqueous-Speciation/1-Introduction-to-Aq-Speciation"
95
+ get_WORM_demo(demo_name, URL)
96
+
97
+ def get_multi_aqueous_speciation_demo():
98
+ demo_name = "Demo-3-2-Multi-Aqueous_Speciation"
99
+ URL = "3-Aqueous-Speciation/2-Multi-Sample-Speciation"
100
+ get_WORM_demo(demo_name, URL)
101
+
102
+ def get_charge_balance_demo():
103
+ demo_name = "Demo-3-3-Charge-Balance"
104
+ URL = "3-Aqueous-Speciation/3-Charge-Balancing"
105
+ get_WORM_demo(demo_name, URL)
106
+
107
+ def get_heterogeneous_equilibrium_demo():
108
+ demo_name = "Demo-3-4-1-Heterogeneous-Equilibrium"
109
+ URL = "3-Aqueous-Speciation/4-Custom-Database/1-Introduction"
110
+ get_WORM_demo(demo_name, URL)
111
+
112
+ def get_heterogeneous_equilibrium_gas_demo():
113
+ demo_name = "Demo-3-4-2-Gas-Equilibrium"
114
+ URL = "3-Aqueous-Speciation/Heterogeneous-Equil-Dissolve-Gas"
115
+ get_WORM_demo(demo_name, URL)
116
+
117
+ def get_alter_suppress_demo():
118
+ demo_name = "Demo-3-5-Alter-Suppress"
119
+ URL = "3-Aqueous-Speciation/5-Alter-and-Suppress"
120
+ get_WORM_demo(demo_name, URL)
121
+
122
+ def get_EQ3_demo():
123
+ demo_name = "Demo-3-6-1-EQ3"
124
+ URL = "3-Aqueous-Speciation/6-Extras/speciate-3i-file"
125
+ get_WORM_demo(demo_name, URL)
126
+
127
+ def get_EQ6_demo():
128
+ demo_name = "Demo-3-6-2-EQ6"
129
+ URL = "3-Aqueous-Speciation/6-Extras/speciate-6i-file"
130
+ get_WORM_demo(demo_name, URL)
131
+
132
+ def get_custom_data0_demo():
133
+ demo_name = "Demo-3-6-3-Custom-data0"
134
+ URL = "3-Aqueous-Speciation/4-Custom-Database/2-Creating-data0-files"
135
+ get_WORM_demo(demo_name, URL)
136
+
137
+ def get_intro_mass_transfer_demo():
138
+ demo_name = "Demo-3-7-1-Intro-Mass-Transfer"
139
+ URL = "3-Aqueous-Speciation/7-Mass-Transfer/1-Introduction"
140
+ get_WORM_demo(demo_name, URL)
141
+
142
+ def get_mass_transfer_feature_demo():
143
+ demo_name = "Demo-3-7-2-Mass-Transfer-Features"
144
+ URL = "3-Aqueous-Speciation/7-Mass-Transfer/2-Feature-Demo"
145
+ get_WORM_demo(demo_name, URL)
146
+
147
+ def get_mixing_demo():
148
+ demo_name = "Demo-3-7-3-Mixing-Fluids"
149
+ URL = "3-Aqueous-Speciation/7-Mass-Transfer/3-Fluid-Mixing"
150
+ get_WORM_demo(demo_name, URL)
151
+
152
+ def get_speciation_datasets_demo():
153
+ demo_name = "Demo-3-8-Dataset-Exploration"
154
+ URL = "3-Aqueous-Speciation/6-Extras/speciation-datasets"
155
+ get_WORM_demo(demo_name, URL)
156
+
157
+ def get_energy_supply_demo():
158
+ demo_name = "Demo-3-9-Energy-Supplies"
159
+ URL = "3-Aqueous-Speciation/Intro-to-Energy-Supplies"
160
+ get_WORM_demo(demo_name, URL)
161
+
162
+ def get_intro_aqorg_demo():
163
+ demo_name = "Demo-4-1-1-Intro-AqOrg"
164
+ URL = "4-Thermodynamic-Property-Estimation"
165
+ get_WORM_demo(demo_name, URL)
166
+
167
+ def get_aqorg_feature_demo():
168
+ demo_name = "Demo-4-1-2-AqOrg-Features"
169
+ URL = "4-Thermodynamic-Property-Estimation/Aq-Organics-Feature-Demo"
170
+ get_WORM_demo(demo_name, URL)
171
+
172
+ def get_propfit_demo():
173
+ demo_name = "propfit tutorial"
174
+ URL = "4-Thermodynamic-Property-Estimation/PropFit"
175
+ get_WORM_demo(demo_name, URL)
176
+
177
+ def get_complicator_demo():
178
+ demo_name = "Demo-4-2-1-WORM-Complicator"
179
+ URL = "4-Thermodynamic-Property-Estimation/Complicator"
180
+ get_WORM_demo(demo_name, URL)
181
+
182
+ def get_estimate_HKF_demo():
183
+ demo_name = "Demo-4-3-Estimate-HKF-Parameters"
184
+ URL = "4-Thermodynamic-Property-Estimation/Estimate-HKF-Parameters"
185
+ get_WORM_demo(demo_name, URL)
186
+
187
+ def get_Weeks_2025_demo():
188
+ demo_name = "Demo-5-Ammonia-Speciation-Weeks-et-al-2025"
189
+ URL = "5-Community-WORM-Notebooks/Ammonia-Speciation-Weeks-et-al-2025"
190
+ get_WORM_demo(demo_name, URL)
191
+
192
+ def get_Trinh_2026_demo():
193
+ demo_name = "Demo-5-Europa-Methanogenesis-Trinh-et-al-2026"
194
+ URL = "5-Community-WORM-Notebooks/Europa-Methanogenesis-Trinh-et-al-2026"
195
+ get_WORM_demo(demo_name, URL)
196
+
197
+ def get_whats_in_water_demo():
198
+ demo_name = "Demo-5-Whats-In-Your-Water-Weeks-Debes-2025"
199
+ URL = "5-Community-WORM-Notebooks/Whats-In-Your-Water-Weeks-Debes-2025"
200
+ get_WORM_demo(demo_name, URL)
201
+
202
+ def get_workshop_demo(workshop_name):
203
+ demo_name = "Demo-Workshop-"+workshop_name
204
+ URL = "WORKSHOP"
205
+ get_WORM_demo(demo_name, URL)
206
+
207
+ def delete_all_demos():
208
+ path = os.getcwd()
209
+ pattern = os.path.join(path, "Demo-*")
210
+
211
+ for item in glob(pattern):
212
+ if not os.path.isdir(item):
213
+ continue
214
+ rmtree(item)
215
+
216
+ def get_library_notebook():
217
+ """Download the latest WORM-Library.ipynb notebook to the current working directory."""
218
+ URL_raw_prefix = 'https://raw.githubusercontent.com/worm-portal/WORM-Library/master/'
219
+ filename = 'WORM-Library.ipynb'
220
+
221
+ with urlopen(URL_raw_prefix + filename) as webpage:
222
+ content = webpage.read().decode()
223
+
224
+ with open(filename, 'w', encoding='utf-8') as output:
225
+ output.write(content)
226
+
227
+ print(f"{filename} downloaded successfully.")
@@ -1,6 +1,6 @@
1
1
  from .downloader import get_worm_tour, get_introduction_demo
2
2
  from .downloader import get_reaction_properties_demo, get_univariant_curve_demo
3
3
  from .downloader import get_intro_aqueous_speciation_demo, get_multi_aqueous_speciation_demo, get_charge_balance_demo, get_heterogeneous_equilibrium_demo, get_heterogeneous_equilibrium_gas_demo, get_alter_suppress_demo, get_custom_data0_demo, get_EQ3_demo, get_EQ6_demo, get_intro_mass_transfer_demo, get_mass_transfer_feature_demo, get_mixing_demo, get_speciation_datasets_demo, get_energy_supply_demo
4
- from .downloader import get_intro_aqorg_demo, get_aqorg_feature_demo, get_complicator_demo, get_estimate_HKF_demo
4
+ from .downloader import get_intro_aqorg_demo, get_aqorg_feature_demo, get_propfit_demo, get_complicator_demo, get_estimate_HKF_demo
5
5
  from .downloader import get_workshop_demo, delete_all_demos, get_library_notebook
6
6
  from .downloader import get_Weeks_2025_demo, get_Trinh_2026_demo, get_whats_in_water_demo
@@ -36,11 +36,11 @@ def get_WORM_demo(demo_name, URL):
36
36
  try:
37
37
  gitstr = str([s for s in soup.find_all('script') if "payload" in str(s)][0])
38
38
  gitstr = gitstr.split(">")[1].split("<")[0]
39
- repo_files = [d["path"].split(URL+"/")[1] for d in json.loads(gitstr)["payload"]["tree"]["items"]]
39
+ repo_files = [d["path"].split(URL+"/")[1] for d in json.loads(gitstr)["payload"]["codeViewTreeRoute"]["tree"]["items"]]
40
40
  except:
41
41
  gitstr = str([s for s in soup.find_all('script') if "payload" in str(s)][1])
42
42
  gitstr = gitstr.split(">")[1].split("<")[0]
43
- repo_files = [d["path"].split(URL+"/")[1] for d in json.loads(gitstr)["payload"]["tree"]["items"]]
43
+ repo_files = [d["path"].split(URL+"/")[1] for d in json.loads(gitstr)["payload"]["codeViewTreeRoute"]["tree"]["items"]]
44
44
 
45
45
  # correct for ampersand in file names
46
46
  # e.g., S&amp;C10vents.csv becomes S&C10vents.csv
@@ -169,6 +169,11 @@ def get_aqorg_feature_demo():
169
169
  URL = "4-Thermodynamic-Property-Estimation/Aq-Organics-Feature-Demo"
170
170
  get_WORM_demo(demo_name, URL)
171
171
 
172
+ def get_propfit_demo():
173
+ demo_name = "propfit_tutorial"
174
+ URL = "4-Thermodynamic-Property-Estimation/PropFit"
175
+ get_WORM_demo(demo_name, URL)
176
+
172
177
  def get_complicator_demo():
173
178
  demo_name = "Demo-4-2-1-WORM-Complicator"
174
179
  URL = "4-Thermodynamic-Property-Estimation/Complicator"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: worm_library
3
- Version: 1.2.2
3
+ Version: 1.3.0
4
4
  Summary: Download WORM Portal tutorial notebooks and files
5
5
  Author-email: Grayson Boyer <gmboyer@asu.edu>
6
6
  License-Expression: MIT
@@ -8,4 +8,6 @@ worm_library.egg-info/PKG-INFO
8
8
  worm_library.egg-info/SOURCES.txt
9
9
  worm_library.egg-info/dependency_links.txt
10
10
  worm_library.egg-info/requires.txt
11
- worm_library.egg-info/top_level.txt
11
+ worm_library.egg-info/top_level.txt
12
+ worm_library/.ipynb_checkpoints/__init__-checkpoint.py
13
+ worm_library/.ipynb_checkpoints/downloader-checkpoint.py
File without changes
File without changes
File without changes
File without changes