DrTrigon has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/104520


Change subject: bugfix; <class 'locale.Error'>: unsupported locale setting (use 
'utf8' locales) improvement; check db existence in case of error only
......................................................................

bugfix; <class 'locale.Error'>: unsupported locale setting (use 'utf8' locales)
improvement; check db existence in case of error only

Change-Id: Id6042f43a943afaa0fd1e1f39677c004ae4a2fdc
---
M public_html/cgi-bin/sum_cat_disc.py
1 file changed, 15 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/bots/drtrigonbot 
refs/changes/20/104520/1

diff --git a/public_html/cgi-bin/sum_cat_disc.py 
b/public_html/cgi-bin/sum_cat_disc.py
index 16d3c40..1e26fc9 100755
--- a/public_html/cgi-bin/sum_cat_disc.py
+++ b/public_html/cgi-bin/sum_cat_disc.py
@@ -344,7 +344,10 @@
        period = form.getvalue('period', '24')
 
        lang = locale.locale_alias.get(wiki, 
locale.locale_alias['en']).split('.')[0]
-       locale.setlocale(locale.LC_TIME, lang)
+       try:
+               locale.setlocale(locale.LC_TIME, lang + '.utf8')
+       except locale.Error:
+               locale.setlocale(locale.LC_TIME, lang)
 
        #scheme = {'NO': 'http', 'YES': 
'https'}[os.environ.get('HTTP_X_TS_SSL', 'NO')]
 
@@ -437,18 +440,21 @@
 
 site = pywikibot.getSite(wiki)
 
-# check existence of user database (for temporary table to join with)
-db = MySQLdb.connect(host=wiki+db_conf[1], read_default_file=cnf_file)
-cursor = db.cursor()
-call_db(_SQL_create_database % db_name)
-cursor.close()
-db.close()
-
 # Establich a connection
 #db = MySQLdb.connect(db='enwiki_p', host="enwiki-p.rrdb.toolserver.org", 
read_default_file="/home/drtrigon/.my.cnf")
 #db = MySQLdb.connect(db=wiki+'wiki_p', 
host=wiki+"wiki-p.rrdb.toolserver.org", 
read_default_file="/home/drtrigon/.my.cnf")
 #db = MySQLdb.connect(db='u_drtrigon', 
host=wiki+"wiki-p.userdb.toolserver.org", 
read_default_file="/home/drtrigon/.my.cnf")
-db = MySQLdb.connect(db=db_name, host=wiki+db_conf[1], 
read_default_file=cnf_file)
+try:
+       db = MySQLdb.connect(db=db_name, host=wiki+db_conf[1], 
read_default_file=cnf_file)
+except _mysql_exceptions.OperationalError:
+       # check existence of user database (for temporary table to join with)
+       db = MySQLdb.connect(host=wiki+db_conf[1], read_default_file=cnf_file)
+       cursor = db.cursor()
+       call_db(_SQL_create_database % db_name)
+       cursor.close()
+       db.close()
+       # re-try to connect
+       db = MySQLdb.connect(db=db_name, host=wiki+db_conf[1], 
read_default_file=cnf_file)
 # prepare a cursor object using cursor() method
 cursor = db.cursor()
 

-- 
To view, visit https://gerrit.wikimedia.org/r/104520
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id6042f43a943afaa0fd1e1f39677c004ae4a2fdc
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/bots/drtrigonbot
Gerrit-Branch: master
Gerrit-Owner: DrTrigon <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to