oafuncs 0.0.70__py2.py3-none-any.whl → 0.0.72__py2.py3-none-any.whl

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.
@@ -4,7 +4,7 @@
4
4
  Author: Liu Kun && 16031215@qq.com
5
5
  Date: 2024-11-01 10:31:09
6
6
  LastEditors: Liu Kun && 16031215@qq.com
7
- LastEditTime: 2024-12-01 10:57:04
7
+ LastEditTime: 2024-12-01 11:45:18
8
8
  FilePath: \\Python\\My_Funcs\\OAFuncs\\oafuncs\\oa_down\\hycom_3hourly.py
9
9
  Description:
10
10
  EditPlatform: vscode
@@ -602,6 +602,31 @@ def dlownload_file(target_url, store_path, file_name, check=False):
602
602
  request_times = 0
603
603
  filename = Path(store_path) / file_name
604
604
 
605
+ def calculate_wait_time(time_str):
606
+ import re
607
+
608
+ # 定义正则表达式,匹配YYYYMMDDHH格式的时间
609
+ time_pattern = r'\d{10}'
610
+
611
+ # 定义两个字符串
612
+ # str1 = 'HYCOM_water_u_2018010100_2018010112.nc'
613
+ # str2 = 'HYCOM_water_u_2018010100.nc'
614
+
615
+ # 使用正则表达式查找时间
616
+ times_in_str = re.findall(time_pattern, time_str)
617
+
618
+ # 计算每个字符串中的时间数量
619
+ num_times_str = len(times_in_str)
620
+
621
+ if num_times_str > 1:
622
+ delta_t = datetime.datetime.strptime(times_in_str[1], '%Y%m%d%H') - datetime.datetime.strptime(times_in_str[0], '%Y%m%d%H')
623
+ delta_t = delta_t.total_seconds() / 3600
624
+ delta_t = delta_t / 3 + 1
625
+
626
+ return int(delta_t*15)
627
+
628
+ max_timeout = calculate_wait_time(file_name)
629
+
605
630
  if check:
606
631
  if check_existing_file(filename):
607
632
  return
@@ -620,7 +645,7 @@ def dlownload_file(target_url, store_path, file_name, check=False):
620
645
  # 尝试下载文件
621
646
  try:
622
647
  headers = {'User-Agent': get_ua()}
623
- response = s.get(target_url, headers=headers, timeout=random.randint(5, 15))
648
+ response = s.get(target_url, headers=headers, timeout=random.randint(5, max_timeout))
624
649
  response.raise_for_status() # 如果请求返回的不是200,将抛出HTTPError异常
625
650
 
626
651
  # 保存文件
@@ -730,6 +755,8 @@ def prepare_url_to_download(var, lon_min=0, lon_max=359.92, lat_min=-80, lat_max
730
755
  var = var[0]
731
756
  submit_url = get_submit_url_var(var, depth, level_num, lon_min, lon_max, lat_min, lat_max, dataset_name, version_name, download_time, download_time_end)
732
757
  file_name = f"HYCOM_{variable_info[var]['var_name']}_{download_time}.nc"
758
+ if download_time_end is not None:
759
+ file_name = f"HYCOM_{variable_info[var]['var_name']}_{download_time}_{download_time_end}.nc"
733
760
  dlownload_file(submit_url, store_path, file_name, check)
734
761
  else:
735
762
  varlist = [_ for _ in var]
@@ -752,6 +779,8 @@ def prepare_url_to_download(var, lon_min=0, lon_max=359.92, lat_min=-80, lat_max
752
779
  submit_url = submit_url.replace(old_str, new_str)
753
780
  # file_name = f'HYCOM_{'-'.join([variable_info[v]["var_name"] for v in current_group])}_{download_time}.nc'
754
781
  file_name = f'HYCOM_{key}_{download_time}.nc'
782
+ if download_time_end is not None:
783
+ file_name = f'HYCOM_{key}_{download_time}_{download_time_end}.nc'
755
784
  dlownload_file(submit_url, store_path, file_name, check)
756
785
 
757
786
 
@@ -779,7 +808,7 @@ def download_task(var, time_str, time_str_end, lon_min, lon_max, lat_min, lat_ma
779
808
  prepare_url_to_download(var, lon_min, lon_max, lat_min, lat_max, time_str, time_str_end, depth, level, store_path, dataset_name, version_name, check)
780
809
 
781
810
 
782
- def download_hourly_func(var, time_s, time_e=None, lon_min=0, lon_max=359.92, lat_min=-80, lat_max=90, depth=None, level=None, store_path=None, dataset_name=None, version_name=None, num_workers=None, check=False, ftimes=1):
811
+ def download_hourly_func(var, time_s, time_e, lon_min=0, lon_max=359.92, lat_min=-80, lat_max=90, depth=None, level=None, store_path=None, dataset_name=None, version_name=None, num_workers=None, check=False, ftimes=1):
783
812
  '''
784
813
  Description:
785
814
  Download the data of single time or a series of time
@@ -802,15 +831,7 @@ def download_hourly_func(var, time_s, time_e=None, lon_min=0, lon_max=359.92, la
802
831
  Returns:
803
832
  None
804
833
  '''
805
- ymdh_time_s = str(time_s)
806
- if len(ymdh_time_s) == 8:
807
- ymdh_time_s += '00'
808
- if time_e is None:
809
- ymdh_time_e = ymdh_time_s[:]
810
- else:
811
- ymdh_time_e = str(time_e)
812
- if len(ymdh_time_e) == 8:
813
- ymdh_time_e += '21'
834
+ ymdh_time_s, ymdh_time_e = str(time_s), str(time_e)
814
835
  if ymdh_time_s == ymdh_time_e:
815
836
  prepare_url_to_download(var, lon_min, lon_max, lat_min, lat_max, ymdh_time_s, None, depth, level, store_path, dataset_name, version_name)
816
837
  elif int(ymdh_time_s) < int(ymdh_time_e):
@@ -826,10 +847,6 @@ def download_hourly_func(var, time_s, time_e=None, lon_min=0, lon_max=359.92, la
826
847
  progress.update(task, advance=1, description=f'[cyan]Downloading... {i+1}/{len(time_list)}')
827
848
  else:
828
849
  # 并行方式
829
- if num_workers > 10:
830
- print('The number of workers is too large!')
831
- print('In order to avoid the server being blocked, the number of workers is set to 10')
832
- num_workers = 10
833
850
  with ThreadPoolExecutor(max_workers=num_workers) as executor:
834
851
  futures = [executor.submit(download_task, var, time_str, None, lon_min, lon_max, lat_min, lat_max, depth, level, store_path, dataset_name, version_name, check) for time_str in time_list]
835
852
  for i, future in enumerate(futures):
@@ -846,16 +863,12 @@ def download_hourly_func(var, time_s, time_e=None, lon_min=0, lon_max=359.92, la
846
863
  progress.update(task, advance=1, description=f'[cyan]Downloading... {i+1}/{total_num}')
847
864
  else:
848
865
  # 并行方式
849
- if num_workers > 10:
850
- print('The number of workers is too large!')
851
- print('In order to avoid the server being blocked, the number of workers is set to 10')
852
- num_workers = 10
853
866
  with ThreadPoolExecutor(max_workers=num_workers) as executor:
854
867
  futures = [executor.submit(download_task, var, new_time_list[i], time_list[int(min(len(time_list), int(i*ftimes+ftimes-1)))], lon_min, lon_max, lat_min, lat_max, depth, level, store_path, dataset_name, version_name, check) for i in range(total_num)]
855
868
  for i, future in enumerate(futures):
856
869
  future.add_done_callback(lambda _: progress.update(task, advance=1, description=f'[cyan]Downloading... {i+1}/{total_num}'))
857
870
  else:
858
- print('Please ensure the time_s is less than the time_e')
871
+ print('Please ensure the time_s is no more than time_e')
859
872
 
860
873
 
861
874
  def download(var, time_s, time_e=None, lon_min=0, lon_max=359.92, lat_min=-80, lat_max=90, depth=None, level=None, store_path=None, dataset_name=None, version_name=None, num_workers=None, check=False, ftimes=1):
@@ -923,6 +936,19 @@ def download(var, time_s, time_e=None, lon_min=0, lon_max=359.92, lat_min=-80, l
923
936
  else:
924
937
  os.makedirs(str(store_path), exist_ok=True)
925
938
 
939
+ if num_workers is not None:
940
+ num_workers = max(min(num_workers, 10), 1)
941
+
942
+ time_s = str(time_s)
943
+ if len(time_s) == 8:
944
+ time_s += '00'
945
+ if time_e is None:
946
+ time_e = time_s[:]
947
+ else:
948
+ time_e = str(time_e)
949
+ if len(time_e) == 8:
950
+ time_e += '21'
951
+
926
952
  download_hourly_func(var, time_s, time_e, lon_min, lon_max, lat_min, lat_max, depth, level, store_path, dataset_name, version_name, num_workers, check, ftimes)
927
953
 
928
954
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: oafuncs
3
- Version: 0.0.70
3
+ Version: 0.0.72
4
4
  Summary: My short description for my project.
5
5
  Home-page: https://github.com/Industry-Pays/OAFuncs
6
6
  Author: Kun Liu
@@ -7,7 +7,7 @@ oafuncs/oa_help.py,sha256=ppNktmtNzs15R20MD1bM7yImlTQ_ngMwvoIglePOKXA,1000
7
7
  oafuncs/oa_nc.py,sha256=ALAYfqDy5lbUNJsTU29j6ZWkM4wgqQU3p2Fxn5pkvsQ,12102
8
8
  oafuncs/oa_python.py,sha256=XPTP3o7zTFzfJR_YhsKfQksa3bSYwXsne9YxlJplCEA,3994
9
9
  oafuncs/oa_down/__init__.py,sha256=a6rgxHQi8spvlI-TaVEqnrDNhYsKm5_IQf7ckAZ8U4w,603
10
- oafuncs/oa_down/hycom_3hourly.py,sha256=ATKA-p-gLTUR4MInzN5yql1sCKi8C9nvQ_yXqjMwzQI,56655
10
+ oafuncs/oa_down/hycom_3hourly.py,sha256=aVyZk8hs5tPH0DYvhKQIFwor2RkJHZGIXnwGKr2o_iY,57394
11
11
  oafuncs/oa_down/literature.py,sha256=dT3-7-beEzQ9mTP8LNV9Gf3q5Z1Pqqjc6FOS010HZeQ,17833
12
12
  oafuncs/oa_down/refs_pdf.py,sha256=lgGKO2gQ0hRjuaBYOLeBgksJB_KXYpFcXMDwMQeYVkI,18719
13
13
  oafuncs/oa_sign/__init__.py,sha256=QKqTFrJDFK40C5uvk48GlRRbGFzO40rgkYwu6dYxatM,563
@@ -16,8 +16,8 @@ oafuncs/oa_sign/ocean.py,sha256=xrW-rWD7xBWsB5PuCyEwQ1Q_RDKq2KCLz-LOONHgldU,5932
16
16
  oafuncs/oa_sign/scientific.py,sha256=a4JxOBgm9vzNZKpJ_GQIQf7cokkraV5nh23HGbmTYKw,5064
17
17
  oafuncs/oa_tool/__init__.py,sha256=IKOlqpWlb4cMDCtq2VKR_RTxQHDNqR_vfqqsOsp_lKQ,466
18
18
  oafuncs/oa_tool/email.py,sha256=4lJxV_KUzhxgLYfVwYTqp0qxRugD7fvsZkXDe5WkUKo,3052
19
- oafuncs-0.0.70.dist-info/LICENSE.txt,sha256=rMtLpVg8sKiSlwClfR9w_Dd_5WubTQgoOzE2PDFxzs4,1074
20
- oafuncs-0.0.70.dist-info/METADATA,sha256=6u5-PblWLD9YmMabXD7zKarROPKOxaoSTSHmwGXKqQ4,22531
21
- oafuncs-0.0.70.dist-info/WHEEL,sha256=pxeNX5JdtCe58PUSYP9upmc7jdRPgvT0Gm9kb1SHlVw,109
22
- oafuncs-0.0.70.dist-info/top_level.txt,sha256=bgC35QkXbN4EmPHEveg_xGIZ5i9NNPYWqtJqaKqTPsQ,8
23
- oafuncs-0.0.70.dist-info/RECORD,,
19
+ oafuncs-0.0.72.dist-info/LICENSE.txt,sha256=rMtLpVg8sKiSlwClfR9w_Dd_5WubTQgoOzE2PDFxzs4,1074
20
+ oafuncs-0.0.72.dist-info/METADATA,sha256=yMP6PaG4mCkJt6Jcm9o5M7kgcEON-tBkwVGK9N9Rkqw,22531
21
+ oafuncs-0.0.72.dist-info/WHEEL,sha256=pxeNX5JdtCe58PUSYP9upmc7jdRPgvT0Gm9kb1SHlVw,109
22
+ oafuncs-0.0.72.dist-info/top_level.txt,sha256=bgC35QkXbN4EmPHEveg_xGIZ5i9NNPYWqtJqaKqTPsQ,8
23
+ oafuncs-0.0.72.dist-info/RECORD,,