def generate(self): started_loading = time.time() self.reset() self.add_archives_and_tags() finish_loading = time.time() logger.info( "Loaded config and %s posts in %.3fs" % (len(self.posts), finish_loading - started_loading) ) if self.posts: self.generate_posts() self.generate_tags() self.generate_archives() self.generate_feed() self.generate_pages() else: logger.warning("Can't find any post.") self.generate_other_pages() self.copy_static_files() self.renderer.render_sitemap() finish_generating = time.time() logger.info( "Generated %s posts in %.3fs" % (len(self.posts), finish_generating - finish_loading) ) logger.info( "Generating finished in %.3fs" % (finish_generating - started_loading) )
def search_github(name): repo_name = "catsup-theme-{name}".format(name=name) url = "https://api.github.com/search/repositories?q=" + repo_name request = urllib2.Request(url) request.add_header("User-Agent", "Catsup Theme Finder") try: response = urllib2.urlopen(request) except urllib2.HTTPError as e: logger.warning("Error when connecting to GitHub: {}".format(e.msg)) return None content = response.read() json = ujson.loads(content) if json["total_count"] == 0: return None for item in json["items"]: if item["name"] == repo_name: return {"name": item["name"], "clone_url": item["clone_url"]}
def search_github(name): repo_name = "catsup-theme-{name}".format(name=name) response = requests.get("https://api.github.com/search/repositories?q={repo_name}".format(repo_name=repo_name), headers={ "User-Agent": "Catsup Theme Finder" }) try: response.raise_for_status() except requests.HTTPError: logger.warning("Error when connecting to GitHub.") return None json = response.json() if json["total_count"] == 0: return None for item in json["items"]: if item["name"] == repo_name: return { "name": item["name"], "clone_url": item["clone_url"] }
def search_github(name): repo_name = "catsup-theme-{name}".format(name=name) url = "https://api.github.com/search/repositories?q=" + repo_name request = urllib2.Request(url) request.add_header("User-Agent", "Catsup Theme Finder") try: response = urllib2.urlopen(request) except urllib2.HTTPError as e: logger.warning("Error when connecting to GitHub: {}".format(e.msg)) return None content = response.read() json = ujson.loads(content) if json["total_count"] == 0: return None for item in json["items"]: if item["name"] == repo_name: return { "name": item["name"], "clone_url": item["clone_url"] }
def create_config_file(path=None): if path: os.chdir(path) current_dir = os.getcwd() config_path = os.path.join(current_dir, 'config.json') if os.path.exists(config_path): from catsup.logger import logger logger.warning("Config file already exist.") exit(1) mkdir("posts") mkdir("static") template = get_template() with open(config_path, 'w') as f: f.write(template) print('Created a new config file.' 'Please configure your blog by editing config.json')