Created
September 19, 2012 00:29
-
-
Save pcote/3746933 to your computer and use it in GitHub Desktop.
Gist File Loader Idea for Blender
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
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