Skip to content

Commit

Permalink
make a master manager
Browse files Browse the repository at this point in the history
other fixes
fix scrape paid new_task
  • Loading branch information
datawhores committed Aug 24, 2024
1 parent 2b6d212 commit c8b6505
Show file tree
Hide file tree
Showing 34 changed files with 208 additions and 181 deletions.
4 changes: 2 additions & 2 deletions ofscraper/actions/actions/download/batch/downloadbatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from ofscraper.actions.actions.download.utils.text import textDownloader
from ofscraper.utils.args.accessors.areas import get_download_area
platform_name = platform.system()
from ofscraper.runner.manager import Manager
import ofscraper.runner.manager as manager



Expand Down Expand Up @@ -96,7 +96,7 @@ async def process_dicts(username, model_id, filtered_medialist, posts):
stdout_logqueues[i][1],
connect_tuples[i][1],
dates.getLogDate(),
Manager.model_manager.all_subs_dict,
manager.Manager.model_manager.all_subs_dict,
read_args.retriveArgs(),
),
)
Expand Down
4 changes: 2 additions & 2 deletions ofscraper/actions/actions/like/like.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import random
import time

import ofscraper.classes.sessionmanager.ofsession as sessionManager
import ofscraper.runner.manager as manager2
import ofscraper.utils.args.accessors.read as read_args
import ofscraper.utils.cache as cache
import ofscraper.utils.constants as constants
Expand Down Expand Up @@ -104,7 +104,7 @@ def _like(model_id, username, ids: list, like_action: bool):

like_func = _toggle_like_requests if like_action else _toggle_unlike_requests
with progress_utils.setup_like_progress_live():
with sessionManager.OFSessionManager(
with manager2.Manager.get_ofsession(
sem_count=1,
backend="httpx",
retries=constants.getattr("API_LIKE_NUM_TRIES"),
Expand Down
4 changes: 2 additions & 2 deletions ofscraper/actions/actions/metadata/batch/metadatabatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from ofscraper.actions.utils.threads import handle_threads, start_threads
from ofscraper.actions.actions.metadata.batch.utils.queue import queue_process
from ofscraper.actions.actions.metadata.utils.desc import desc
from ofscraper.runner.manager import Manager
import ofscraper.runner.manager as manager


platform_name = platform.system()
Expand Down Expand Up @@ -83,7 +83,7 @@ def process_dicts(username, model_id, filtered_medialist):
stdout_logqueues[i][1],
connect_tuples[i][1],
dates.getLogDate(),
Manager.model_manager.all_subs_dict,
manager.Manager.model_manager.all_subs_dict,
read_args.retriveArgs(),
),
)
Expand Down
7 changes: 3 additions & 4 deletions ofscraper/actions/utils/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
from ofscraper.utils.logs.stdout import add_stdout_handler_multi
from ofscraper.utils.logs.other import add_other_handler_multi
import ofscraper.utils.logs.logger as logger
import ofscraper.data.models.selector as selector
import ofscraper.utils.args.mutators.write as write_args
import ofscraper.utils.dates as dates
from ofscraper.actions.utils.send.message import set_send_msg
from ofscraper.runner.manager import Manager
import ofscraper.runner.manager as manager



Expand Down Expand Up @@ -80,8 +79,8 @@ def subProcessVariableInit(
set_up_contexvars()
write_args.setArgs(argsCopy)
dates.setLogDate(dateDict)
Manager.start_managers()
Manager.model_manager.all_subs_dict=userList
manager.start_other_managers()
manager.manager.Manager.model_manager.all_subs_dict=userList
process_split_globals(pipeCopy, stdout_logqueue, file_logqueue)
set_send_msg()

Expand Down
5 changes: 3 additions & 2 deletions ofscraper/classes/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
from async_property import async_cached_property

import ofscraper.classes.base as base
import ofscraper.classes.sessionmanager.ofsession as sessionManager
import ofscraper.utils.args.accessors.quality as quality
import ofscraper.utils.config.data as data
import ofscraper.utils.constants as constants
import ofscraper.utils.dates as dates
import ofscraper.utils.logs.utils.level as log_helpers
import ofscraper.runner.manager as manager2


warnings.filterwarnings("ignore", category=MarkupResemblesLocatorWarning)

Expand Down Expand Up @@ -389,7 +390,7 @@ async def parse_mpd(self):
"Signature": self.signature,
}
async with self._lock:
async with sessionManager.OFSessionManager(
async with manager2.Manager.aget_ofsession(
retries=constants.getattr("MPD_NUM_TRIES"),
wait_min=constants.getattr("OF_MIN_WAIT_API"),
wait_max=constants.getattr("OF_MAX_WAIT_API"),
Expand Down
13 changes: 6 additions & 7 deletions ofscraper/classes/placeholder.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import logging
import random
import string
import os
import pathlib
import re

import arrow

import ofscraper.data.models.selector as selector
import ofscraper.utils.args.accessors.read as read_args
import ofscraper.utils.cache as cache
import ofscraper.utils.config.custom as custom_
Expand All @@ -20,6 +17,8 @@
import ofscraper.utils.profiles.data as profile_data
import ofscraper.utils.settings as settings
from ofscraper.utils.string import parse_safe
import ofscraper.runner.manager as manager


log = logging.getLogger("shared")

Expand Down Expand Up @@ -197,7 +196,7 @@ async def init(self):
return self

def add_price_variables(self, username):
modelObj = selector.get_model_fromParsed(username)
modelObj = manager.Manager.model_manager.get_model_fromParsed(username)
self._variables.update(
{
"current_price": (
Expand Down Expand Up @@ -259,7 +258,7 @@ async def add_main_variables(self, ele, username, model_id):
self._variables.update({"response_type": ele.modified_responsetype})
self._variables.update({"label": ele.label_string})
self._variables.update({"download_type": ele.downloadtype})
self._variables.update({"modelObj": selector.get_model_fromParsed(username)})
self._variables.update({"modelObj": manager.Manager.model_manager.get_model_fromParsed(username)})
self._variables.update({"quality": await ele.selected_quality_placeholder})
self._variables.update({"file_name": await ele.final_filename})
self._variables.update({"original_filename": ele.filename})
Expand Down Expand Up @@ -433,7 +432,7 @@ async def init(self):
return self

def add_price_variables(self, username):
modelObj = selector.get_model_fromParsed(username)
modelObj = manager.Manager.model_manager.get_model_fromParsed(username)
self._variables.update(
{
"current_price": (
Expand Down Expand Up @@ -489,7 +488,7 @@ async def add_main_variables(self, ele, username, model_id):
self._variables.update({"media_type": "Text"})
self._variables.update({"response_type": ele.modified_responsetype})
self._variables.update({"label": ele.label_string})
self._variables.update({"modelObj": selector.get_model_fromParsed(username)})
self._variables.update({"modelObj": manager.Manager.model_manager.get_model_fromParsed(username)})
self._variables.update({"text": ele.text_trunicate(ele.file_sanitized_text)})
self._variables.update({"config": config_file.open_config()})
self._variables.update({"args": read_args.retriveArgs()})
Expand Down
5 changes: 2 additions & 3 deletions ofscraper/commands/managers/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@


import ofscraper.utils.args.accessors.read as read_args
import ofscraper.utils.console as console
from ofscraper.__version__ import __version__
import ofscraper.utils.constants as constants
import ofscraper.utils.live.screens as progress_utils
import ofscraper.utils.live.updater as progress_updater
from ofscraper.data.posts.post import post_media_process
import ofscraper.filters.media.main as filters
import ofscraper.data.models.selector as selector
import ofscraper.utils.args.accessors.areas as areas
import ofscraper.utils.live.tasks as progress_tasks
from ofscraper.commands.utils.strings import (
Expand All @@ -23,6 +21,7 @@


log = logging.getLogger("shared")
import ofscraper.runner.manager as manager


class commmandManager:
Expand Down Expand Up @@ -166,7 +165,7 @@ def _data_helper(self, user):
username = user.name
active = user.active
final_post_areas = areas.get_final_posts_area()
length = selector.get_num_selected()
length =manager.Manager.model_manager.get_num_selected()
count = progress_tasks.get_user_task_obj().completed
logging.getLogger("shared_other").warning(
progress_str.format(count=count + 1, length=length)
Expand Down
19 changes: 10 additions & 9 deletions ofscraper/commands/runners/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@
import ofscraper.classes.table.table as table
import ofscraper.db.operations as operations
import ofscraper.actions.actions.download.normal.downloadnormal as downloadnormal
import ofscraper.data.models.selector as selector
import ofscraper.data.models.manager as manager
import ofscraper.utils.args.accessors.read as read_args
import ofscraper.utils.args.mutators.write as write_args
import ofscraper.utils.auth.request as auth_requests
import ofscraper.utils.console as console_
import ofscraper.utils.constants as constants
import ofscraper.utils.live.screens as progress_utils
import ofscraper.utils.live.updater as progress_updater
import ofscraper.utils.settings as settings
import ofscraper.utils.system.network as network
from ofscraper.data.api.common.check import read_check, reset_check, set_check
from ofscraper.data.api.common.timeline import get_individual_timeline_post
Expand All @@ -48,6 +47,8 @@
from ofscraper.runner.close.final.final_user import post_user_script
from ofscraper.runner.close.final.final import final
from ofscraper.utils.args.accessors.command import get_command
import ofscraper.runner.manager as manager




Expand Down Expand Up @@ -114,7 +115,7 @@ def process_item():
raise Exception(f"No data for {media_id}_{post_id}_{username}")
log.info(f"Added url {media.url or media.mpd}")
log.info("Sending URLs to OF-Scraper")
selector.set_data_all_subs_dict(username)
manager.Manager.model_manager.set_data_all_subs_dict(username)
post = media.post
model_id = media.post.model_id
username = media.post.username
Expand Down Expand Up @@ -153,7 +154,7 @@ def update_globals(model_id, username, post, media, values):
"media": [],
"username": username,
"model_id": model_id,
"userdata": selector.get_model_fromParsed(username),
"userdata": manager.Manager.model_manager.get_model_fromParsed(username),
"results": values,
},
)
Expand Down Expand Up @@ -235,7 +236,7 @@ async def post_check_runner():
async def post_check_retriver():
user_dict = {}
links = list(url_helper())
async with sessionManager.OFSessionManager(
async with manager.Manager.aget_ofsession(
backend="httpx",
sem_count=constants.getattr("API_REQ_CHECK_MAX"),
) as c:
Expand Down Expand Up @@ -415,7 +416,7 @@ async def message_checker_runner():

async def message_check_retriver():
links = list(url_helper())
async with sessionManager.OFSessionManager(
async with manager.Manager.aget_ofsession(
backend="httpx",
) as c:
for item in links:
Expand Down Expand Up @@ -494,7 +495,7 @@ async def purchase_checker_runner():
async def purchase_check_retriver():
user_dict = {}
auth_requests.make_headers()
async with sessionManager.OFSessionManager(
async with manager.Manager.aget_ofsession(
backend="httpx",
sem_count=constants.getattr("API_REQ_CHECK_MAX"),
) as c:
Expand Down Expand Up @@ -549,7 +550,7 @@ async def stories_checker_runner():
@run
async def stories_check_retriver():
user_dict = {}
async with sessionManager.OFSessionManager(
async with manager.Manager.aget_ofsession(
backend="httpx",
sem_count=constants.getattr("API_REQ_CHECK_MAX"),
) as c:
Expand Down Expand Up @@ -621,7 +622,7 @@ async def get_paid_ids(model_id, user_name):
if len(oldpaid) > 0 and not read_args.retriveArgs().force:
paid = oldpaid
else:
async with sessionManager.OFSessionManager(
async with manager.Manager.aget_ofsession(
backend="httpx", sem_count=constants.getattr("API_REQ_CHECK_MAX")
) as c:
paid = await paid_.get_paid_posts(model_id, user_name, c=c)
Expand Down
10 changes: 6 additions & 4 deletions ofscraper/commands/runners/manual.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import ofscraper.data.api.profile as profile
import ofscraper.classes.media as media_
import ofscraper.classes.posts as posts_
import ofscraper.classes.sessionmanager.ofsession as sessionManager
import ofscraper.runner.manager as manager2
import ofscraper.db.operations as operations
import ofscraper.actions.actions.download.download as download
import ofscraper.data.models.selector as selector
import ofscraper.data.models.manager as manager
import ofscraper.utils.args.accessors.read as read_args
import ofscraper.utils.args.mutators.write as write_args
import ofscraper.utils.constants as constants
Expand All @@ -27,6 +27,8 @@
from ofscraper.utils.context.run_async import run
from ofscraper.runner.close.final.final import final
from ofscraper.actions.actions.download.utils.text import textDownloader
import ofscraper.runner.manager as manager



def manual_download(urls=None):
Expand Down Expand Up @@ -111,7 +113,7 @@ def allow_manual_dupes():


def set_user_data(url_dicts):
selector.set_data_all_subs_dict(
manager.Manager.model_manager.set_data_all_subs_dict(
[nested_dict.get("username") for nested_dict in url_dicts.values()]
)

Expand Down Expand Up @@ -241,7 +243,7 @@ async def paid_failback(post_id, model_id, username):
"Using failback search because query return 0 media"
)
post_id = str(post_id)
async with sessionManager.OFSessionManager(
async with manager.Manager.aget_ofsession(
backend="httpx",
sem_count=constants.getattr("API_REQ_CHECK_MAX"),
) as c:
Expand Down
8 changes: 4 additions & 4 deletions ofscraper/commands/runners/metadata/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import logging

import ofscraper.data.api.init as init
import ofscraper.classes.sessionmanager.ofsession as sessionManager
import ofscraper.runner.manager as manager2
import ofscraper.utils.actions as actions
import ofscraper.utils.args.accessors.read as read_args
import ofscraper.utils.constants as constants
Expand All @@ -25,7 +25,7 @@
from ofscraper.runner.close.final.final import final
from ofscraper.utils.checkers import check_auth
from ofscraper.commands.managers.metadata import metadataCommandManager
from ofscraper.runner.manager import Manager
import ofscraper.runner.manager as manager


log = logging.getLogger("shared")
Expand Down Expand Up @@ -68,8 +68,8 @@ def prepare():
profile_tools.print_current_profile()
actions.select_areas()
init.print_sign_status()
userdata =Manager.model_manager.getselected_usernames(rescan=False)
session = sessionManager.OFSessionManager(
userdata =manager.Manager.model_manager.getselected_usernames(rescan=False)
session = manager2.Manager.get_ofsession(
sem_count=constants.getattr("API_REQ_SEM_MAX"),
total_timeout=constants.getattr("API_TIMEOUT_PER_TASK"),
)
Expand Down
8 changes: 4 additions & 4 deletions ofscraper/commands/runners/scraper/utils/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
import time

import ofscraper.data.api.init as init
import ofscraper.classes.sessionmanager.ofsession as sessionManager
import ofscraper.runner.manager as manager2
import ofscraper.utils.actions as actions
import ofscraper.utils.constants as constants
import ofscraper.utils.profiles.tools as profile_tools
import ofscraper.classes.placeholder as placeholder
from ofscraper.runner.manager import Manager
import ofscraper.runner.manager as manager


log = logging.getLogger("shared")


def prepare(menu=False):
session = sessionManager.OFSessionManager(
session = manager2.Manager.get_ofsession(
sem_count=constants.getattr("API_REQ_SEM_MAX"),
total_timeout=constants.getattr("API_TIMEOUT_PER_TASK"),
)
Expand All @@ -26,7 +26,7 @@ def prepare(menu=False):
if menu is True:
actions.set_scrape_paid()

userdata = Manager.model_manager.getselected_usernames(rescan=False)
userdata = manager.Manager.model_manager.getselected_usernames(rescan=False)
return userdata, session


Expand Down
Loading

0 comments on commit c8b6505

Please sign in to comment.