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

بوت:أرشفة صفحات نقاش المستخدمين #165

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added tasks/archive/__init__.py
Empty file.
Empty file added tasks/archive/users/__init__.py
Empty file.
39 changes: 39 additions & 0 deletions tasks/archive/users/module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import wikitextparser as wtp

from core.utils.helpers import prepare_str

template_name = "أرشفة آلية"


def read_archive_template(page_text, archive_template_name):
# Parse the page text using the wikitextparser library
parsed = wtp.parse(page_text)

# Set default values for template type and value
template_type = 'section'
template_value = 10

# Loop over all templates in the parsed page text
for template in parsed.templates:
# Check if the current template is the archive template we are looking for
if prepare_str(template.name) == prepare_str(archive_template_name):
try:
# Attempt to parse the template type string from the first argument of the template
template_type_str = prepare_str(template.arguments[0].value)
if template_type_str == prepare_str('حجم'):
template_type = 'size'
elif template_type_str == prepare_str('قسم'):
template_type = 'section'
except:
# If an error occurs while parsing the template type, skip this block and use the default value
pass
try:
# Attempt to parse the template value integer from the second argument of the template
template_value_str = template.arguments[1].value
template_value = int(template_value_str)
except:
# If an error occurs while parsing the template value, skip this block and use the default value
pass

# Return the template type and value
return template_type, template_value
16 changes: 16 additions & 0 deletions tasks/archive/users/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pywikibot

from tasks.archive.users.module import template_name, read_archive_template

site = pywikibot.Site()

template = pywikibot.Page(site, f"قالب:{template_name}")

gen = template.embeddedin(filter_redirects=False, namespaces=3, content=True)

for user_talk in gen:
if user_talk.depth == 0:
print(user_talk)
template_type, template_value = read_archive_template(page_text=user_talk.text,
archive_template_name=template_name)
print(template_type, template_value)