Skip to content

Commit 7a424cd

Browse files
authored
Merge pull request #109 from aviolaris/2.1.x
2.1.x
2 parents 938b03c + bfdc57b commit 7a424cd

File tree

7 files changed

+356
-155
lines changed

7 files changed

+356
-155
lines changed

.dockerignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
/.git
22
/.github
33
/.idea
4-
/.pytest_cache
4+
/.pytest_cache
5+
/tests
6+
README.md
7+
README.gr.md
8+
LICENSE.md

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ARG PYTHON_VERSION=3.12
2-
FROM alpine:3.20.1 as build-stage
2+
FROM alpine:3.20.1 AS build-stage
33
ARG PYTHON_VERSION
44
COPY . /app/instaunfollowers/
55
RUN apk add --no-cache python3~=${PYTHON_VERSION} py3-pip

app/app.py

Lines changed: 63 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
"""Imports"""
22
import logging
33
import os.path
4+
import platform
45
import re
56
import zipfile
6-
import multiprocessing
7-
from gunicorn.app.base import BaseApplication
87
from flask import Flask, render_template, request, redirect, url_for, session
98
from flask_paginate import Pagination
109
from werkzeug.utils import secure_filename
@@ -27,7 +26,7 @@
2726
# Upload folder
2827
UPLOAD_FOLDER = os.path.join(os.getcwd(), 'uploads')
2928
# Current version
30-
CURRENT_VERSION = 'v2.0.0'
29+
CURRENT_VERSION = 'v2.1.0'
3130
# Update needed
3231
UPDATE_NEEDED = bool(update_needed(CURRENT_VERSION, get_latest_version()))
3332

@@ -36,13 +35,14 @@ def create_upload_dir():
3635
"""
3736
Create the upload directory if it does not exist.
3837
"""
39-
try:
40-
os.makedirs(UPLOAD_FOLDER)
41-
logging.info("Directory %s created successfully.", {UPLOAD_FOLDER})
42-
except FileExistsError:
43-
logging.info("Directory %s already exists.", {UPLOAD_FOLDER})
44-
except OSError as exc:
45-
logging.error("Error creating directory: %s", {exc})
38+
if not os.path.exists(UPLOAD_FOLDER):
39+
try:
40+
os.makedirs(UPLOAD_FOLDER)
41+
logging.info("Directory %s created successfully.", UPLOAD_FOLDER)
42+
except OSError as exc:
43+
logging.error("Error creating directory: %s", exc)
44+
else:
45+
logging.info("Directory %s already exists.", UPLOAD_FOLDER)
4646

4747

4848
def parse_usernames(html_source):
@@ -172,56 +172,63 @@ def unfollowers():
172172
per_page=per_page,
173173
pagination=pagination, )
174174

175+
if platform.system() != "Windows":
176+
from gunicorn.app.base import BaseApplication
177+
import multiprocessing
175178

176-
class InstaUnFollowers(BaseApplication):
177-
"""
178-
This class extends the `gunicorn.app.base.BaseApplication` class and
179-
provides custom implementation for the `load_config` and `load` methods.
180-
181-
Attributes:
182-
options (dict): Options for the application.
183-
application (obj): The application object.
184-
185-
Args:
186-
application (obj): The application object.
187-
options (dict, optional): Options for the Gunicorn server.
188-
189-
Note:
190-
'init' and 'load' methods are implemented by WSGIApplication.
191-
"""
192-
193-
# pylint: disable=abstract-method
194-
def __init__(self, application, options=None):
195-
self.options = options or {}
196-
self.application = application
197-
super().__init__()
198-
199-
def load_config(self):
179+
class InstaUnFollowers(BaseApplication):
200180
"""
201-
Load the configuration for the Gunicorn server.
181+
This class extends the `gunicorn.app.base.BaseApplication` class and
182+
provides custom implementation for the `load_config` and `load` methods.
202183
203-
This method sets the Gunicorn server configuration values based on the provided options.
204-
"""
205-
config = {key: value for key, value in self.options.items()
206-
if key in self.cfg.settings and value is not None}
207-
for key, value in config.items():
208-
self.cfg.set(key.lower(), value)
184+
Attributes:
185+
options (dict): Options for the application.
186+
application (obj): The application object.
209187
210-
def load(self):
211-
"""
212-
Load the application.
188+
Args:
189+
application (obj): The application object.
190+
options (dict, optional): Options for the Gunicorn server.
213191
214-
Returns:
215-
obj: The application object.
192+
Note:
193+
'init' and 'load' methods are implemented by WSGIApplication.
216194
"""
217-
return self.application
218-
219195

220-
if __name__ == '__main__':
221-
create_upload_dir()
222-
gunicorn_options = {
223-
'bind': '0.0.0.0:5000',
224-
'workers': (multiprocessing.cpu_count() * 2) + 1,
225-
'timeout': 500,
226-
}
227-
InstaUnFollowers(app, gunicorn_options).run()
196+
# pylint: disable=abstract-method
197+
def __init__(self, application, options=None):
198+
self.options = options or {}
199+
self.application = application
200+
super().__init__()
201+
202+
def load_config(self):
203+
"""
204+
Load the configuration for the Gunicorn server.
205+
206+
This method sets the Gunicorn server configuration values based on the provided options.
207+
"""
208+
config = {key: value for key, value in self.options.items()
209+
if key in self.cfg.settings and value is not None}
210+
for key, value in config.items():
211+
self.cfg.set(key.lower(), value)
212+
213+
def load(self):
214+
"""
215+
Load the application.
216+
217+
Returns:
218+
obj: The application object.
219+
"""
220+
return self.application
221+
222+
223+
if __name__ == '__main__':
224+
create_upload_dir()
225+
gunicorn_options = {
226+
'bind': '0.0.0.0:5000',
227+
'workers': (multiprocessing.cpu_count() * 2) + 1,
228+
'timeout': 500,
229+
}
230+
InstaUnFollowers(app, gunicorn_options).run()
231+
else:
232+
if __name__ == '__main__':
233+
create_upload_dir()
234+
app.run(debug=True, host="0.0.0.0", port=5000)

app/healthcheck.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ def fetch_url(url):
2828
sys.exit(1)
2929

3030

31-
fetch_url('http://localhost:5000')
31+
if __name__ == "__main__":
32+
fetch_url('http://localhost:5000')

0 commit comments

Comments
 (0)