diff --git a/.gitignore b/.gitignore index 265b088..c01dab5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ -scraper/ +scraper/** +!scraper/*.py .venv/ __pycache__/ +static/ posts/ \ No newline at end of file diff --git a/style.css b/assets/style.css similarity index 100% rename from style.css rename to assets/style.css diff --git a/blog.html b/blog.html deleted file mode 100644 index 63b2d71..0000000 --- a/blog.html +++ /dev/null @@ -1,164 +0,0 @@ - - - - - - Rochester Food Not Bombs - - - - - - - - - -

Blog not bombs ;)

-
- -
- - post image from Feb 10, '25 -

Feb 10, '25

-
-
- -
- - post image from Feb  9, '25 -

Feb 9, '25

-
-
- -
- - post image from Feb  9, '25 -

Feb 9, '25

-
-
- -
- - post image from Feb  6, '25 -

Feb 6, '25

-
-
- -
- - post image from Feb  5, '25 -

Feb 5, '25

-
-
- -
- - post image from Feb  3, '25 -

Feb 3, '25

-
-
- -
- - post image from Feb  2, '25 -

Feb 2, '25

-
-
- -
- - post image from Jan 31, '25 -

Jan 31, '25

-
-
- -
- - post image from Jan 29, '25 -

Jan 29, '25

-
-
- -
- - post image from Jan 27, '25 -

Jan 27, '25

-
-
- -
- - post image from Jan 26, '25 -

Jan 26, '25

-
-
- -
- - post image from Jan 24, '25 -

Jan 24, '25

-
-
- -
- - post image from Jan 23, '25 -

Jan 23, '25

-
-
- -
- - post image from Jan 22, '25 -

Jan 22, '25

-
-
- -
- - post image from Jan 21, '25 -

Jan 21, '25

-
-
- -
- - post image from Jan 21, '25 -

Jan 21, '25

-
-
- -
- - post image from Jan 20, '25 -

Jan 20, '25

-
-
- -
- - post image from Jan 19, '25 -

Jan 19, '25

-
-
- -
- - post image from Jan 19, '25 -

Jan 19, '25

-
-
- -
- - - - \ No newline at end of file diff --git a/builder.py b/builder.py index 33aa8c5..ffcb0a1 100644 --- a/builder.py +++ b/builder.py @@ -5,10 +5,11 @@ import re from pytz import timezone from datetime import datetime import bisect +import shutil from jinja2 import Environment, PackageLoader, select_autoescape scraper_path = 'scraper/' -output_path='./' +output_path='./static' env = Environment( loader=PackageLoader("builder"), @@ -17,6 +18,12 @@ env = Environment( blog_template = env.get_template("blog_template.html") post_template=env.get_template("post.html") +try: + os.makedirs(output_path) +except FileExistsError as err: + if not os.path.isdir(output_path): + raise RuntimeError(f'output path {output_path} exists and is not a directory') from err + posts = [] for folder in os.listdir(scraper_path): @@ -54,13 +61,16 @@ for folder in os.listdir(scraper_path): post['caption'] = file.read() if ('timestamp' in post.keys()): - with open(output_path + 'posts/' + str(post['timestamp']) +'.html', 'w+') as output_file: + with open('posts/' + str(post['timestamp']) +'.html', 'w+') as output_file: output_file.write(post_template.render(post=post)) homepage_template = env.get_template("index.html") -with open(output_path + 'index.html', "w+") as output_file: +with open(output_path + '/index.html', "w+") as output_file: output_file.write(homepage_template.render()) -with open(output_path + 'blog.html', "w+") as output_file: - output_file.write(blog_template.render(posts=posts)) \ No newline at end of file +with open(output_path + '/blog.html', "w+") as output_file: + output_file.write(blog_template.render(posts=posts)) + +# copy all assets to be in the output +shutil.copytree('assets/', 'static/', dirs_exist_ok=True) \ No newline at end of file diff --git a/index.html b/index.html deleted file mode 100644 index d107104..0000000 --- a/index.html +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - Rochester Food Not Bombs - - - - - - - - - - -

Rochester Food Not Bombs!

-Solidarity not charity: From Rochester, New York. -

Free hot meals are served every Saturday at 6:30PM in front of the RTS Transit Center on St. Paul.

-

Help us cook every Saturday at 4PM at the Flying Squirrel Community Space. -

-
- -
-

Quick resources

- -
- -
-

Rochester Food Not Bombs recovers resources to create free vegetarian and vegan meals in our local - community. - We - are a decentralized all-volunteer run group, with no hierarchy or formal leaders, making decisions based - on - consensus.

-

- We recognize poverty as a form of violence, and think access to food should be viewed as a right, rather - than a - privilege. In this practice, we strive to reduce waste by turning donated food into productive meals. We - source - food from vendors at the Public Market, as well as relying on donations. Food should be a source of - nutrition - for - people, not profit under capitalism. Through Community organizing and outreach, we support other local - and - national peace and justice groups to create a broader sense of social responsibility -- If you would - like to - get - involved, please reach out to us! -

-
-
-

See what we're up to :-)

- - - - \ No newline at end of file diff --git a/scraper/scraper.py b/scraper/scraper.py new file mode 100644 index 0000000..ceb6d17 --- /dev/null +++ b/scraper/scraper.py @@ -0,0 +1,18 @@ +# wait between 1050 and 1150 seconds +import instaloader +from time import sleep +from random import randint +from os import listdir + +L = instaloader.Instaloader() + +L.load_session_from_file("down.loader54321") + +profile_of_interest = instaloader.Profile.from_username(L.context, "rocfnb") +files = listdir('.') +for post in profile_of_interest.get_posts(): + if not post.shortcode in files : + L.download_post(post, target=post.shortcode) + sleep(randint(1050, 1150)) + else: + print("Already downloaded " + post.shortcode +", skipping...") \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 9400839..f2ddb84 100644 --- a/templates/index.html +++ b/templates/index.html @@ -12,16 +12,16 @@ Solidarity not charity: From Rochester, New York.

Quick resources

@@ -49,5 +49,5 @@ Solidarity not charity: From Rochester, New York.

-

See what we're up to :-)

+ {% endblock %} \ No newline at end of file