Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.1.x #109

Merged
merged 8 commits into from
Oct 13, 2024
6 changes: 5 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/.git
/.github
/.idea
/.pytest_cache
/.pytest_cache
/tests
README.md
README.gr.md
LICENSE.md
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG PYTHON_VERSION=3.12
FROM alpine:3.20.1 as build-stage
FROM alpine:3.20.1 AS build-stage
ARG PYTHON_VERSION
COPY . /app/instaunfollowers/
RUN apk add --no-cache python3~=${PYTHON_VERSION} py3-pip
Expand Down
119 changes: 63 additions & 56 deletions app/app.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""Imports"""
import logging
import os.path
import platform
import re
import zipfile
import multiprocessing
from gunicorn.app.base import BaseApplication
from flask import Flask, render_template, request, redirect, url_for, session
from flask_paginate import Pagination
from werkzeug.utils import secure_filename
Expand All @@ -27,7 +26,7 @@
# Upload folder
UPLOAD_FOLDER = os.path.join(os.getcwd(), 'uploads')
# Current version
CURRENT_VERSION = 'v2.0.0'
CURRENT_VERSION = 'v2.1.0'
# Update needed
UPDATE_NEEDED = bool(update_needed(CURRENT_VERSION, get_latest_version()))

Expand All @@ -36,13 +35,14 @@ def create_upload_dir():
"""
Create the upload directory if it does not exist.
"""
try:
os.makedirs(UPLOAD_FOLDER)
logging.info("Directory %s created successfully.", {UPLOAD_FOLDER})
except FileExistsError:
logging.info("Directory %s already exists.", {UPLOAD_FOLDER})
except OSError as exc:
logging.error("Error creating directory: %s", {exc})
if not os.path.exists(UPLOAD_FOLDER):
try:
os.makedirs(UPLOAD_FOLDER)
logging.info("Directory %s created successfully.", UPLOAD_FOLDER)
except OSError as exc:
logging.error("Error creating directory: %s", exc)
else:
logging.info("Directory %s already exists.", UPLOAD_FOLDER)


def parse_usernames(html_source):
Expand Down Expand Up @@ -172,56 +172,63 @@ def unfollowers():
per_page=per_page,
pagination=pagination, )

if platform.system() != "Windows":
from gunicorn.app.base import BaseApplication
import multiprocessing

class InstaUnFollowers(BaseApplication):
"""
This class extends the `gunicorn.app.base.BaseApplication` class and
provides custom implementation for the `load_config` and `load` methods.

Attributes:
options (dict): Options for the application.
application (obj): The application object.

Args:
application (obj): The application object.
options (dict, optional): Options for the Gunicorn server.

Note:
'init' and 'load' methods are implemented by WSGIApplication.
"""

# pylint: disable=abstract-method
def __init__(self, application, options=None):
self.options = options or {}
self.application = application
super().__init__()

def load_config(self):
class InstaUnFollowers(BaseApplication):
"""
Load the configuration for the Gunicorn server.
This class extends the `gunicorn.app.base.BaseApplication` class and
provides custom implementation for the `load_config` and `load` methods.

This method sets the Gunicorn server configuration values based on the provided options.
"""
config = {key: value for key, value in self.options.items()
if key in self.cfg.settings and value is not None}
for key, value in config.items():
self.cfg.set(key.lower(), value)
Attributes:
options (dict): Options for the application.
application (obj): The application object.

def load(self):
"""
Load the application.
Args:
application (obj): The application object.
options (dict, optional): Options for the Gunicorn server.

Returns:
obj: The application object.
Note:
'init' and 'load' methods are implemented by WSGIApplication.
"""
return self.application


if __name__ == '__main__':
create_upload_dir()
gunicorn_options = {
'bind': '0.0.0.0:5000',
'workers': (multiprocessing.cpu_count() * 2) + 1,
'timeout': 500,
}
InstaUnFollowers(app, gunicorn_options).run()
# pylint: disable=abstract-method
def __init__(self, application, options=None):
self.options = options or {}
self.application = application
super().__init__()

def load_config(self):
"""
Load the configuration for the Gunicorn server.

This method sets the Gunicorn server configuration values based on the provided options.
"""
config = {key: value for key, value in self.options.items()
if key in self.cfg.settings and value is not None}
for key, value in config.items():
self.cfg.set(key.lower(), value)

def load(self):
"""
Load the application.

Returns:
obj: The application object.
"""
return self.application


if __name__ == '__main__':
create_upload_dir()
gunicorn_options = {
'bind': '0.0.0.0:5000',
'workers': (multiprocessing.cpu_count() * 2) + 1,
'timeout': 500,
}
InstaUnFollowers(app, gunicorn_options).run()
else:
if __name__ == '__main__':
create_upload_dir()
app.run(debug=True, host="0.0.0.0", port=5000)
3 changes: 2 additions & 1 deletion app/healthcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ def fetch_url(url):
sys.exit(1)


fetch_url('http://localhost:5000')
if __name__ == "__main__":
fetch_url('http://localhost:5000')
Loading