예제 #1
0
def update_project(project):
    """Updates the duration of the project's time"""
    duration = None

    # set local timezone
    timezone = get_localzone()
    local_tz = timezone.zone

    # collect all of the logs that are part of this project
    logs = Log.select().where(Log.project_id == project.id)

    # iterate over the logs and accumulate the duration of each log
    for n, log in enumerate(logs):
        start = parse(log.start_time).datetime(to_timezone=local_tz,
                                               naive=True)
        stop = parse(log.stop_time).datetime(to_timezone=local_tz, naive=True)

        if n == 0:
            duration = MayaInterval.from_datetime(start, stop).timedelta
        else:
            duration += MayaInterval.from_datetime(start, stop).timedelta

    # update the project
    project.duration = duration
    project.status = 0
    project.save()
    print('Deactivating: {} with total time of {}'.format(
        project.name, project.duration))
예제 #2
0
def main():
    a = maya.now()
    print(a)
    print(a.iso8601())
    print(a.slang_date())
    print(a.slang_time())
    print(a.day)
    print(a.month)
    print(a.year)
    print(a.epoch)
    print(a.rfc2822())
    print(a.rfc3339())
    print(a.datetime())
    print(a.hour, a.minute, a.second, a.microsecond)

    tm = '2019-11-22 16:37:45.423992+00:00'
    print(maya.parse(tm).datetime())
    print(maya.parse(tm).datetime(to_timezone='US/Eastern', naive=True))
    print(maya.parse(tm).datetime(to_timezone='ASIA/Shanghai', naive=True))

    b = maya.get_localzone()
    print(b)

    # rand_day = maya.when('2011-02-07', timezone='US/Eastern')
    # print(rand_day)

    rand_day = maya.when('2019-11-22', timezone='ASIA/Shanghai')
    print(rand_day)
    print(rand_day.day, rand_day.month, rand_day.year)

    from datetime import datetime
    d = maya.MayaDT.from_datetime(datetime.utcnow())
    print(d)

    import time
    e = maya.MayaDT.from_struct(time.gmtime())
    print(e)
    f = maya.MayaDT(time.time())
    print(f)
예제 #3
0
 def get_local_timezone_name():
     print(time.localtime().tm_isdst)
     return maya.get_localzone()
예제 #4
0
파일: google.py 프로젝트: sefcom/dbling
    def __init__(self,
                 http=None,
                 impersonated_user_email=None,
                 start=None,
                 end=None,
                 timezone=None):
        """
        :param httplib2.Http http: An Http object for sending the requests. In
            general, this should be left as None, which will allow for
            auto-adjustment of the kind of Http object to create based on
            whether a user's email address is to be impersonated.
        :param str impersonated_user_email: The email address of a user to
            impersonate. This requires domain-wide delegation to be activated.
            See
            https://developers.google.com/admin-sdk/reports/v1/guides/delegation
            for instructions.
        :param str start: The earliest data to collect. Can be any kind of date
            string, as long as it is unambiguous (e.g. "2017"). It can even be
            slang, such as "a year ago". Be aware, however, that only the *day*
            of the date will be used, meaning *time* information will be
            discarded.
        :param str end: The latest data to collect. Same format rules apply for
            this as for the ``start`` parameter.
        :param str timezone: The timezone to convert all timestamps to before
            compiling. This should be a standard timezone name. For reference,
            the list that the timezone will be compared against is available at
            https://github.com/newvem/pytz/blob/master/pytz/__init__.py. If
            omitted, the local timezone of the computer will be used.
        """
        if NotImplemented in (self._service_name, self._version):
            raise ValueError(
                'Implementing classes of GoogleAPI must set a value for _service_name and _version.'
            )

        self.email = impersonated_user_email

        # By default, set the timezone to whatever the local timezone is. Otherwise set it to what the user specified.
        if timezone is None or timezone not in all_timezones:
            self.tz = str(get_localzone())
        else:
            self.tz = timezone

        # Interpret the start and end times
        if start is None:
            self.start = start
        else:
            try:
                self.start = parse(start).datetime().date(
                )  # First, assume they gave a well-formatted time
            except ValueError:
                self.start = when(start).datetime().date(
                )  # Next, attempt to interpret the time as slang

        if end is None:
            self.end = end
        else:
            try:
                self.end = parse(end).datetime().date()
            except ValueError:
                self.end = when(end).datetime().date()

        self.customer_id = 'my_customer'  # Only used by directory API

        # The following are accessed by their respective class properties
        self._http = http
        self._service = None
        self._team_drives = None
예제 #5
0
import maya

from collections import OrderedDict
from urllib.parse import urlparse

from scrapy.http import Request
from scrapy.spiders import Rule
from scrapy.linkextractors import LinkExtractor

from hello_spidery.utils.commons import seconds_2_str
from hello_spidery.utils.spiders.crawl_spider import HelloCrawlSpider
from hello_spidery.utils.selector_utils import xpath_extract_all_text_strip, \
    xpath_extract_all_text_no_spaces as xpath_text_no_spaces

LOCAL_TIMEZONE = str(maya.get_localzone())


class MobilePhoneSpider(HelloCrawlSpider):
    name = 'mobile_phone'

    custom_settings = {
        'USE_DEFAULT_ERROR_BACK': True,
        'DOWNLOAD_DELAY': 1,
        'USE_PROXY': True,

        # DATABASE
        'SQLITE_DATABASE': '',
        'CREATE_TABLE_SQL_4_SQLITE': """CREATE TABLE IF NOT EXISTS spider_data
                                        (`mobile_phone_number`  char(11) NOT NULL primary key,
                                         `url`                  varchar(100) NOT NULL,