Commit 89df6d84 authored by gijs's avatar gijs
Browse files

Test whether cache dir exists otherwise make it. Some more notes on installation in the readme.

parent a0958013
Visual Culture revisited to be faster, easier to install by using Gitlab API.
# To install
Move into the generator directory:
`cd generator`
Optional, make a virtual environment:
`virtualenv -p python3 venv`
`source venv/bin/activate`
To install the requirements
`pip install -r requirements.txt`
# To generate
`python generate.py`
# To serve:
`python3 -m http.server`
\ No newline at end of file
......@@ -6,7 +6,7 @@ import os.path
import os
import json
import datetime
import time
def debug (msg):
if DEBUG:
......@@ -77,6 +77,7 @@ class ApiCall (object):
url = '{}?{}'.format(url, urlencode(query))
try:
debug('Loading `{}`'.format(url))
res = urlopen(url)
return ({ k: v for (k,v) in res.getheaders() }, self.parse_api_result(res.read()))
except URLError as e:
......@@ -130,11 +131,14 @@ class ApiCallJson(ApiCall):
headers, page_data = self.get_api_url(self.url, query)
data.extend(page_data)
page = int(headers['X-Next-Page']) if headers['X-Next-Page'] else None
if page:
time.sleep(1/3)
except ApiError:
return data
else:
query['per_page'] = 1
_, data = self.get_api_url(self.url, query)
time.sleep(1/3)
return data
......
......@@ -2,15 +2,23 @@ import api
from jinja2 import Environment, FileSystemLoader, select_autoescape
import time
from models import Group
from settings import GROUP_ID, TEMPLATE_DIR, OUTPUT_DIR
from settings import GROUP_ID, TEMPLATE_DIR, OUTPUT_DIR, CACHE_DIR
import os.path
from os import makedirs
from os import makedirs, mkdir
env = Environment(
loader=FileSystemLoader(TEMPLATE_DIR),
autoescape=select_autoescape(['html', 'xml'])
)
print('Starting generation')
if not os.path.exists(OUTPUT_DIR):
mkdir(OUTPUT_DIR)
if not os.path.exists(CACHE_DIR):
mkdir(CACHE_DIR)
group = Group(GROUP_ID)
group.get()
# print(group)
......@@ -46,7 +54,6 @@ group.get()
# print('Loading templates')
# projects = [parse_project(project) for project in get_projects()]
print('Starting generation')
template = env.get_template('projects.html')
template.stream(projects=group.projects).dump(os.path.join(OUTPUT_DIR, 'index.html'))
......
......@@ -7,6 +7,6 @@ OUTPUT_DIR = os.path.join(BASE_DIR, 'output')
API_URL = "https://gitlab.constantvzw.org/api/v4/"
GROUP_ID = 8
DEBUG = False
DEBUG = True
MAX_PAGES = 999
PER_PAGE = 100
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment