#!/usr/bin/python -i import os from stencils.storage import storage from stencils.thingi_page import thingi_index import cProfile p = cProfile.Profile() #s = storage('local',create=1) s = storage('thingiverse_data') def fetch(): l = s.process_list(0) print(str(len(l)) + ' object to fetch ') for j in l: i = j[0] t = s.get_uuid(i) if t.fetch(): print(t.name) s.mark_fetched(i) else: s.mark_broken(i) print('FAIL') print(t) def process(): l = s.process_list(1) print(str(len(l)) + ' object to process') for j in l: i = j[0] t = s.get_uuid(i) try: if t.process(): s.mark_processed(i) else: s.mark_broken(i) except: s.mark_broken(i) def get_newest(start=1,finish=2): for i in range(start,finish): t = thingi_index(s.index,'') t.url = 'http://thingiverse.com/newest/page:'+str(i) t.path = 'cache/thingiverse_data/newest/'+t.uuid t.insert_line(s.index) s.index.db.commit() def load_newest(pages=1): li = os.listdir('cache/thingiverse_data/newest') for i in li[:pages]: print(i) t = thingi_index(s.index,'') t.url = 'http://thingiverse.com/newest/page:1' t.path = 'cache/thingiverse_data/newest/'+i t.processed = 1 t.insert_line(s.index) print(t) s.index.db.commit() def run(): total = 1 while total > 0: fetch() process() total = s.stats() s.index.commit() s.cache = {} tmp = s.index.query("select distinct ftype,count(*) from things group by ftype order by count(*) desc limit 30;") for i in tmp: print(i[0] + ' : '+str(i[1]))