-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
546 additions
and
8,052 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/usr/bin/env python | ||
|
||
""" | ||
Purpose: Standalone script to generate a sitemap.xml from a GitHub | ||
repository containing JSON-LD files, such as | ||
https://github.com/iodepo/odis-arch/tree/master/collection/tempHosting/data-benguelacc | ||
Usage: python benguelacc-sitemap.py | ||
Output: sitemap.xml | ||
Requires: Python 3.x | ||
Note: This assumes that you have checked out the repo files to your | ||
local machine. | ||
Make sure that you set the variable "GITHUB_REPO_LOCAL_PATH" | ||
""" | ||
|
||
# define common variables | ||
GITHUB_REPO_LOCAL_PATH = "E:/iodepo/odis-arch-git/collection/tempHosting/data-benguelacc" | ||
GITHUB_REPO_RAW_BASE_URL = "https://raw.githubusercontent.com/iodepo/odis-arch/master/collection/tempHosting/data-benguelacc/" | ||
NEW_SITEMAP_FILENAME = "sitemap.xml" | ||
|
||
""" | ||
######################### | ||
# you shouldn't have to modify anything below | ||
######################### | ||
""" | ||
|
||
import os, sys | ||
import datetime | ||
|
||
# Get Today's Date to add as Lastmod | ||
lastmod_date = datetime.datetime.now().strftime('%Y-%m-%d') | ||
|
||
# function to print a line of html for the indented hyperlink | ||
def printlink(url): | ||
print (" <url>") | ||
print (" <loc>" + url + "</loc>") | ||
print (" <lastmod>" + lastmod_date + "</lastmod>") | ||
print (" </url>") | ||
return | ||
|
||
original_stdout = sys.stdout # Save a reference to the original standard output | ||
|
||
#create sitemap.xml | ||
with open(NEW_SITEMAP_FILENAME, 'w', newline='\n') as f: | ||
sys.stdout = f # Change the standard output to the file we created. | ||
print ('<?xml version="1.0" encoding="UTF-8"?>') | ||
print ('<urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">') | ||
|
||
#use a Python set, to force unique values | ||
urls = set() | ||
|
||
#loop through directories | ||
for subdir, dirs, files in os.walk(GITHUB_REPO_LOCAL_PATH): | ||
for file in files: | ||
filepath = subdir + os.sep + file | ||
|
||
if filepath.endswith(".json"): | ||
path = os.path.dirname(filepath) | ||
urls.add(GITHUB_REPO_RAW_BASE_URL + file) | ||
|
||
#iterate through unique record urls | ||
for val in urls: | ||
printlink(val) | ||
|
||
print ('</urlset>', end='') | ||
sys.stdout = original_stdout # Reset the standard output to its original value | ||
|
||
print("\n") | ||
print("************************") | ||
print(" " + str(len(urls)) + " records exported to sitemap.xml") | ||
print("************************") | ||
print("\n") |
26 changes: 0 additions & 26 deletions
26
collection/tempHosting/data-benguelacc/benguelacc-180898ac-1406-11ed-9439-0242ac1c0005.json
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
collection/tempHosting/data-benguelacc/benguelacc-7393f4ce-172a-11ed-bc3b-0242ac1c0005.json
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
collection/tempHosting/data-benguelacc/benguelacc-b6236950-1400-11ed-8992-0242ac1c0005.json
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
collection/tempHosting/data-benguelacc/benguelacc-simple-graph-template.json
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.