@@ -22,13 +22,60 @@
|
||||
#
|
||||
#
|
||||
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.engine.url import URL
|
||||
|
||||
import pywikibot
|
||||
|
||||
import jogobot
|
||||
|
||||
|
||||
class MissingNoticeBot():
|
||||
"""
|
||||
"""
|
||||
|
||||
# MySQL-query to get articles with notice
|
||||
cat_article_query = """
|
||||
SELECT `page_title`
|
||||
FROM `categorylinks`
|
||||
JOIN `category`
|
||||
ON `cl_to` = `cat_title`
|
||||
AND `cat_title` LIKE "{cat}\_%%"
|
||||
JOIN `page`
|
||||
ON `cl_from` = `page_id`
|
||||
""".format(cat=jogobot.config["red.missingnotice"]["article_category"])
|
||||
|
||||
def __init__( self, genFactory, **kwargs ):
|
||||
pass
|
||||
|
||||
def run( self ):
|
||||
pass
|
||||
print(type(self).get_categorized_articles() )
|
||||
|
||||
@classmethod
|
||||
def get_categorized_articles( cls ):
|
||||
"""
|
||||
Queries all articles containing the notice based on category set by
|
||||
notice template. Category can be configured in
|
||||
jogobot.config["red.missingnotice"]["article_category"]
|
||||
|
||||
@returns List of all articles containing notice
|
||||
@rtype list
|
||||
"""
|
||||
|
||||
# construct connection url for sqlalchemy
|
||||
url = URL( "mysql+pymysql",
|
||||
username=pywikibot.config.db_username,
|
||||
password=pywikibot.config.db_password,
|
||||
host=jogobot.config["red.missingnotice"]["wikidb_host"],
|
||||
port=jogobot.config["red.missingnotice"]["wikidb_port"],
|
||||
database=jogobot.config["red.missingnotice"]["wikidb_name"],
|
||||
query={'charset': 'utf8'} )
|
||||
|
||||
# create sqlalchemy engine
|
||||
engine = create_engine(url, echo=True)
|
||||
|
||||
# fire the query to get articles with notice
|
||||
result = engine.execute(cls.cat_article_query)
|
||||
|
||||
# return list with articles with notice
|
||||
return [ row['page_title'].decode("utf-8") for row in result ]
|
||||
|
||||
Reference in New Issue
Block a user