1
0
Fork 0

package into main function

This commit is contained in:
Mateusz Konieczny 2025-02-05 18:39:27 +01:00
parent fba8531ec2
commit 1827c90894

View file

@ -6,38 +6,42 @@ import os
import osm_bot_abstraction_layer.util_download_file
config = __import__("0_config")
print(datetime.now().isoformat(timespec='minutes'))
def main():
print(datetime.now().isoformat(timespec='minutes'))
ses = lt.session({'listen_interfaces': '0.0.0.0:6881'})
ses = lt.session({'listen_interfaces': '0.0.0.0:6881'})
torrent_file_directory = config.cache_folder()
filename = 'planet-latest.osm.pbf.torrent'
if os.path.isfile(torrent_file_directory + filename):
os.remove(torrent_file_directory + filename)
print(torrent_file_directory + filename)
url = 'https://planet.openstreetmap.org/pbf/planet-latest.osm.pbf.torrent'
osm_bot_abstraction_layer.util_download_file.download_file_if_not_present_already(url, torrent_file_directory, filename)
torrent_file_directory = config.cache_folder()
filename = 'planet-latest.osm.pbf.torrent'
if os.path.isfile(torrent_file_directory + filename):
os.remove(torrent_file_directory + filename)
print(torrent_file_directory + filename)
url = 'https://planet.openstreetmap.org/pbf/planet-latest.osm.pbf.torrent'
osm_bot_abstraction_layer.util_download_file.download_file_if_not_present_already(url, torrent_file_directory, filename)
info = lt.torrent_info(torrent_file_directory + filename)
h = ses.add_torrent({'ti': info, 'save_path': config.planet_download_folder()})
s = h.status()
print('starting', s.name)
while (not s.is_seeding):
info = lt.torrent_info(torrent_file_directory + filename)
h = ses.add_torrent({'ti': info, 'save_path': config.planet_download_folder()})
s = h.status()
print('starting', s.name)
print('\r%.2f%% complete (down: %.1f kB/s up: %.1f kB/s peers: %d) %s' % (
s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000,
s.num_peers, s.state), end=' ')
while (not s.is_seeding):
s = h.status()
alerts = ses.pop_alerts()
for a in alerts:
if a.category() & lt.alert.category_t.error_notification:
print(a)
print('\r%.2f%% complete (down: %.1f kB/s up: %.1f kB/s peers: %d) %s' % (
s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000,
s.num_peers, s.state), end=' ')
sys.stdout.flush()
alerts = ses.pop_alerts()
for a in alerts:
if a.category() & lt.alert.category_t.error_notification:
print(a)
time.sleep(1)
sys.stdout.flush()
print(h.status().name, 'complete')
print(datetime.now().isoformat(timespec='minutes'))
time.sleep(1)
print(h.status().name, 'complete')
print(datetime.now().isoformat(timespec='minutes'))
if __name__ == "__main__":
main()