Skip to content

Instantly share code, notes, and snippets.

@pcote
Created September 19, 2012 00:29
Show Gist options
  • Save pcote/3746933 to your computer and use it in GitHub Desktop.
Save pcote/3746933 to your computer and use it in GitHub Desktop.
Gist File Loader Idea for Blender
import bpy
import urllib.request as request
import json
import time
user_name = ""
my_url = "https://api.github.com/users/%s/gists" % user_name
json_ob = json.loads(request.urlopen(my_url).read().decode("utf-8"))
gist_set = [x['files'] for x in json_ob]
all_raw_urls = []
for gist in gist_set:
file_names = [key for key in gist.keys()]
raw_urls = [gist[k]['raw_url'] for k in file_names]
all_raw_urls.append(raw_urls[-1])
def load_text(raw_url):
time.sleep(2)
text_name = raw_url.split("/")[-1]
txt = bpy.data.texts.new(text_name)
txt_data = request.urlopen(raw_url).read().decode("utf-8")
txt.write(txt_data)
print("wrote: %s" % text_name)
for url in all_raw_urls:
load_text(url)
print("all done")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment