Browse Source

gist script

Jason 11 months ago
parent
commit
6ea663136f
3 changed files with 21 additions and 1 deletions
  1. 1 0
      .gitignore
  2. 15 0
      scripts/cron.sh
  3. 5 1
      scripts/gists.py

+ 1 - 0
.gitignore

@@ -1,2 +1,3 @@
 content/posts/gist/
 public/
+env/

+ 15 - 0
scripts/cron.sh

@@ -0,0 +1,15 @@
+#!/usr/bin/env  bash
+
+dir="/var/www/jason.schwarzenberger.co.nz"
+cd $dir
+
+git checkout master
+git pull
+
+source ./env/bin/activate
+python $dir/scripts/gists.py
+/home/linuxbrew/.linuxbrew/bin/hugo
+/home/linuxbrew/.linuxbrew/bin/hugo -b https://1j.nz/ -d /var/www/1j.nz/public
+
+chown jason:jason $dir -R
+chown jason:jason /var/www/1j.nz -R

+ 5 - 1
scripts/gists.py

@@ -17,6 +17,7 @@ def main():
 	if not os.path.exists(directory) or not os.path.isdir(directory):
 		os.mkdir(directory)
 
+	print("Fetching gists.")
 	r = requests.get(API_URL)
 	if r.status_code != 200:
 		return
@@ -31,6 +32,7 @@ def main():
 		url = gist.get('html_url')
 		titles = list(files.keys())
 		title = titles[0].strip(".md")
+		print(f"GIST {gist_id} {title}")
 		text = f"""---
 title: "{title}"
 date: {date}
@@ -70,7 +72,9 @@ draft: false
 		subdir = os.path.join(directory, d)
 		if not os.path.exists(subdir) or not os.path.isdir(subdir):
 			os.mkdir(subdir)
-		path = os.path.join(subdir,f'{gist_id}.md')
+		filehash = gist_id if len(gist_id) < 6 else f"{gist_id[:3]}{gist_id[-3:]}"
+		filename = f"{filehash}-{title}.md"
+		path = os.path.join(subdir, filename)
 		with open(path, 'w+') as file:
 			file.write(text)