so I have written a acript that logs into google calendar and pulls the next weeks events and stores them in variables. I am stuck at how to get these variables and put them into a html page does anyone have any ideas? I am running the script once a week and storing the values of the variable and would like to just grab those values and not have to create the html page dynamically every time. Any help is greatly appriciated also not sure if this should go here or under web design(sorry if i posted in wrong group).

Dani AI

Generated

Three practical ways to publish the weekly calendar data without regenerating the page on every request — and what each one buys or costs.

The simplest for a weekly-run script (as posted by ) is to render a static HTML file at script runtime and deploy that file to the webroot. That is the approach mentioned (template engines such as Mako). Workflow: the script fetches events, renders a template and writes a plain index.html. This is fast, cache-friendly, works with bookmarks and search engines, and keeps no runtime secrets in publicly served files.

A slightly more flexible option is to write the data as JSON and keep a largely static HTML shell that loads the JSON with client-side JavaScript (AJAX). That is the pattern suggested. AJAX does not inherently “disable” bookmarks or the back button — the problem is failing to update the URL/history. Use history.pushState/replaceState or hash fragments to provide bookmarkable URLs and popstate/hashchange handlers so back/forward behave as expected. Example sketches:

# Python: write events.json and a rendered index.html
import json
events = get_calendar_events()
with open('events.json','w') as f:
    json.dump(events, f)
# render template -> index.html (use Jinja2/Mako or simple format replacement)
/* JS: fetch data and update history */
fetch('/events.json').then(r=>r.json()).then(data=>{
  document.getElementById('events').innerHTML = renderEvents(data);
  history.replaceState({ts:data.generated_at},'', '?v='+data.generated_at);
});
window.addEventListener('popstate', e => { /* restore UI from e.state */ });

Notes and troubleshooting: never put OAuth tokens or credentials into publicly served files; write only the display data. If the JSON lives on another domain, enable CORS. Use Cache-Control or a version query parameter so browsers refresh weekly. For maximum crawlability/bookmark reliability prefer static HTML generation; use AJAX+history when a single shell page or smaller downloads are preferred.

Recommended Answers

All 3 Replies

Sounds like a job for embedded AJAX, which would read the file with your variables in it, then populate DIV containers on a relatively static HTML page. You wouldn't have to create the entire page each time, and could even have a 'loading' message or something else there until the content is finished loading from your variables. I used something similar for my Pinball Locator some time ago.
I'd say this question is more programming-related than web design, although good skills in the latter would definitely be required to pull this one off.

Ok so Ajax is pretty much the only way to do this then? I read somewhere if u use Ajax to populate a page it disables bookmarks and the back button is this also trueOk so Ajax is pretty much the only way to do this then? I read somewhere if u use Ajax to populate a page it disables bookmarks and the back button is this also true

If you don't want to generate the page dynamically, you can generate it once a week and store an html file when you run your script. You could use a template engine like Mako for variable substitution in the html file. It is very easy to do.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.