This commit is contained in:
		
					parent
					
						
							
								9065887617
							
						
					
				
			
			
				commit
				
					
						e0faa48810
					
				
			
		
					 1 changed files with 55 additions and 0 deletions
				
			
		
							
								
								
									
										55
									
								
								sync.py
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										55
									
								
								sync.py
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,55 @@
 | 
			
		|||
#!/usr/bin/python3
 | 
			
		||||
 | 
			
		||||
from json import loads
 | 
			
		||||
from urllib.request import urlopen
 | 
			
		||||
from zipfile import ZipFile
 | 
			
		||||
from io import BytesIO
 | 
			
		||||
from sys import argv
 | 
			
		||||
from shutil import rmtree
 | 
			
		||||
 | 
			
		||||
def main(destination: str):
 | 
			
		||||
    print("Destination: " + destination)
 | 
			
		||||
 | 
			
		||||
    try:
 | 
			
		||||
        with open(destination + '/site_revision.txt', 'r') as rev_file:
 | 
			
		||||
            saved_run = int(rev_file.read())
 | 
			
		||||
    except:
 | 
			
		||||
        saved_run = -1
 | 
			
		||||
 | 
			
		||||
    print(f"Saved run: {saved_run}")
 | 
			
		||||
 | 
			
		||||
    with urlopen("https://git.m724.eu/api/v1/repos/Minecon724/m724.eu/actions/tasks") as resp:
 | 
			
		||||
        latest_run = loads(resp.read().decode())['workflow_runs'][0]
 | 
			
		||||
 | 
			
		||||
    run_number = int(latest_run["run_number"])
 | 
			
		||||
    run_status = latest_run["status"]
 | 
			
		||||
 | 
			
		||||
    print(f'Latest run: {run_number} "{latest_run["display_title"]}" ({run_status})')
 | 
			
		||||
 | 
			
		||||
    if saved_run == run_number:
 | 
			
		||||
        print("Already at latest")
 | 
			
		||||
        return
 | 
			
		||||
 | 
			
		||||
    if latest_run["status"] != 'success':
 | 
			
		||||
        print("Not syncing, because not success")
 | 
			
		||||
        return
 | 
			
		||||
 | 
			
		||||
    print("Downloading")
 | 
			
		||||
    with urlopen(f"https://git.m724.eu/Minecon724/m724.eu/actions/runs/{run_number}/artifacts/generated_out") as resp:
 | 
			
		||||
        zip_file_content = resp.read()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    rmtree(destination)
 | 
			
		||||
 | 
			
		||||
    print("Extracting")
 | 
			
		||||
    with ZipFile(BytesIO(zip_file_content)) as zip_file:
 | 
			
		||||
        zip_file.extractall(destination)
 | 
			
		||||
 | 
			
		||||
    with open(destination + '/site_revision.txt', 'w') as rev_file:
 | 
			
		||||
        rev_file.write(str(run_number))
 | 
			
		||||
 | 
			
		||||
    print("Done")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    main(argv[1])
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue