コード例 #1
0
ファイル: ukrules.py プロジェクト: jhsoby/UKBot
#encoding=utf-8
from __future__ import unicode_literals
import re
from lxml.html import fromstring
import lxml
from mwtemplates import TemplateEditor
from mwtextextractor import condition_for_lxml
from ukcommon import init_localization
from ukcommon import log
import urllib
import logging

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

t, _ = init_localization()


class Rule(object):

    def __init__(self, key):
        self.key = key

    def iszero(self, f):
        f = float(f)
        return (f > -0.1 and f < 0.1)

    def add_points(self, rev, points, ptype, txt, pmax, include_zero=False):

        ab = rev.article.get_points(ptype)
        ab_raw = rev.article.get_points(ptype, ignore_max=True)
コード例 #2
0
    help='Filename to upload, if empty it is found from the current date')
args = parser.parse_args()

config = yaml.load(open(args.config, 'r'))
wiki_tz = pytz.timezone(config['wiki_timezone'])
server_tz = pytz.timezone(config['server_timezone'])


def unix_time(dt):
    """ OS-independent method to get unix time from a datetime object (strftime('%s') does not work on solaris) """
    epoch = pytz.utc.localize(datetime.utcfromtimestamp(0))
    delta = dt - epoch
    return delta.total_seconds()


_ = init_localization(config['locale'])

runstart = server_tz.localize(datetime.now())
#log('UKBot-uploader starting at %s (server time), %s (wiki time)' % (runstart.strftime('%F %T'), runstart.astimezone(wiki_tz).strftime('%F %T')))

host = config['homesite']
homesite = mwclient.Site(host)

now = server_tz.localize(datetime.now())

if args.page is not None:
    ktitle = args.page.decode('utf-8')
else:
    log('  No page specified. Using default page')
    ktitle = config['pages']['default']
    # subtract a few hours, so we close last week's contest right after midnight
コード例 #3
0
ファイル: uploadplot.py プロジェクト: jhsoby/UKBot
parser.add_argument('--page', required=False, help='Name of the contest page to work with')
parser.add_argument('--filename', nargs='?', help='Filename to upload, if empty it is found from the current date')
args = parser.parse_args()

config = yaml.load(open(args.config, 'r'))
wiki_tz = pytz.timezone(config['wiki_timezone'])
server_tz = pytz.timezone(config['server_timezone'])


def unix_time(dt):
    """ OS-independent method to get unix time from a datetime object (strftime('%s') does not work on solaris) """
    epoch = pytz.utc.localize(datetime.utcfromtimestamp(0))
    delta = dt - epoch
    return delta.total_seconds()

_ = init_localization(config['locale'])

runstart = server_tz.localize(datetime.now())
#log('UKBot-uploader starting at %s (server time), %s (wiki time)' % (runstart.strftime('%F %T'), runstart.astimezone(wiki_tz).strftime('%F %T')))

host = config['homesite']
homesite = mwclient.Site(host)

now = server_tz.localize(datetime.now())

if args.page is not None:
    ktitle = args.page.decode('utf-8')
else:
    log('  No page specified. Using default page')
    ktitle = config['pages']['default']
    # subtract a few hours, so we close last week's contest right after midnight