Exemple #1
0
 def delete_page_content(self, page_id, object_id, last_modified):
     try:
         self.process.DeletePageContent(page_id, object_id, pwt.Time(last_modified))
     except Exception as e: 
         print(e)
         print("Could not Delete Page Content")
Exemple #2
0
from comtypes.automation import IDispatch

# Optional imports
try:
    import pandas as pd
except ImportError:
    pd = None
try:
    import numpy as np
except ImportError:
    np = None

from . import PY3

# Time types: pywintypes.timetype doesn't work on Python 3
time_types = (dt.date, dt.datetime, type(pywintypes.Time(0)))
if np:
    time_types = time_types + (np.datetime64,)


# Constants
OBJID_NATIVEOM = -16


def accessible_object_from_window(hwnd):
    ptr = POINTER(IDispatch)()
    res = oledll.oleacc.AccessibleObjectFromWindow(
        hwnd, OBJID_NATIVEOM,
        byref(IDispatch._iid_), byref(ptr))
    return ptr
Exemple #3
0
 def update_page_content(self, page_changes_xml_in, last_modified):
     try:
         self.process.UpdatePageContent(page_changes_xml_in, pwt.Time(last_modified))
     except Exception as e: 
         print(e)
         print("Could not Update Page Content")
Exemple #4
0
 def testPyTimeCompareOther(self):
     t1 = pywintypes.Time(100)
     t2 = None
     self.failIfEqual(t1, t2)
Exemple #5
0
 def testPyTimeFromTime(self):
     t1 = pywintypes.Time(time.time())
     self.failUnless(pywintypes.Time(t1) is t1)
Exemple #6
0
 def __time_datetime_to_pytime(self, dt_time):
     pyt_time = pywintypes.Time(int(time.mktime(dt_time.timetuple())))
     return pyt_time
Exemple #7
0
 def testTimeInDict(self):
     d = {}
     d["t1"] = pywintypes.Time(1)
     self.failUnlessEqual(d["t1"], pywintypes.Time(1))
        articles = soup.findAll('article')
        for article in articles:
            image = article.find('img',
                                 {'class': ('thumbnail', 'wp-post-image')})
            image_link = image['src'].replace('-1024x576', '')
            file_name = image_link.split("/")[-1]

            date = article.find('span', {'class': 'date'})
            datetime_obj = datetime.datetime.strptime(date.contents[0],
                                                      '%d-%b-%Y')
            download_path = os.path.join(images_dir_name, file_name)

            urllib.request.urlretrieve(image_link, download_path)

            if os.name == 'nt':
                wintime = pywintypes.Time(
                    time.mktime(datetime_obj.utctimetuple()))
                winfile = win32file.CreateFile(
                    download_path, win32con.GENERIC_WRITE,
                    win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE
                    | win32con.FILE_SHARE_DELETE, None, win32con.OPEN_EXISTING,
                    win32con.FILE_ATTRIBUTE_NORMAL, None)

                win32file.SetFileTime(winfile, wintime, None, None)

                winfile.close()

            os.utime(download_path, (time.mktime(datetime_obj.utctimetuple()),
                                     time.mktime(datetime_obj.utctimetuple())))

            last_page_file = open(last_page_file_name, 'w+')
            last_page_file.write(str(current_page))
Exemple #9
0
def yyyy_mm_dd_to_pytime (date_str):
    dt = datetime.strptime(date_str, '%Y-%m-%d')
    return pywintypes.Time(dt.timetuple())
Exemple #10
0
from win32com.test.util import CheckClean

import pywintypes
import win32ui
import win32api, os

from pywin32_testutil import str2bytes

S_OK = 0

import datetime
if issubclass(pywintypes.TimeType, datetime.datetime):
    import win32timezone
    now = win32timezone.now()
else:
    now = pywintypes.Time(time.time())


class LockBytes:
    _public_methods_ = [
        'ReadAt', 'WriteAt', 'Flush', 'SetSize', 'LockRegion', 'UnlockRegion',
        'Stat'
    ]
    _com_interfaces_ = [pythoncom.IID_ILockBytes]

    def __init__(self, data=""):
        self.data = str2bytes(data)
        self.ctime = now
        self.mtime = now
        self.atime = now
Exemple #11
0
    def SvcDoRun(self):
        logging.info("Checking config")
        self.checkConfig()
        self.model = nowcastModel()
      #  logging.info("Starting.....")
        servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
                              servicemanager.PYS_SERVICE_STARTED,(self._svc_name_, ''))
        self.timeout = 60000
        logging.info("Starting SvcDoRun with timeout: %s", self.timeout)
        mb_up = msMBDbInterface(user=self.config['DATABASE']['db_user'],
                                password=self.config['DATABASE']['db_password'],
                                host=self.config['DATABASE']['db_host'], db_name=self.config['DATABASE']['db_name'])
        next_release = mb_up.next_release_date()[0]
        while 1:
            # Wait for service stop signal, if I timeout, loop again
            rc = win32event.WaitForSingleObject(self.hWaitStop, self.timeout)
            if rc == win32event.WAIT_OBJECT_0:
                servicemanager.LogInfoMsg("msDbMBService Stopped")
                break
            else:
                try:
                    servicemanager.LogInfoMsg("msDbMBService Querying Db")
                    logging.info("Opening Db Connection within Service: ")
                    now = datetime.datetime.now()
                    incomplete_indicators = mb_up.find_incorrect_release_dates()
                    data_correct = True
                    if incomplete_indicators:
                        for indicator in incomplete_indicators:
                            logging.info("Fixing indicator: %s", str(indicator[0]))
                            c = win32com.client.Dispatch("Macrobond.Connection")
                            d = c.Database
                            ts = d.FetchOneSeries(str(indicator[0]))
                            releaseName = ts.Metadata.GetFirstValue("Release")
                            releaseEntity = d.FetchOneEntity(releaseName)
                            current_release = releaseEntity.Metadata.GetFirstValue("LastReleaseEventTime")
                            next_release = releaseEntity.Metadata.GetFirstValue("NextReleaseEventTime")
                            success = False
                            if next_release:
                                success = mb_up.fix_incomplete_indicator(indicator, next_release)
                                logging.info("Fixing indicator: %s : Complete", str(indicator[0]))
                            if not success:
                                logging.info("Fixing indicator: %s: Incomplete. Checking again in 1hr", str(indicator[0]))
                                self.timeout = 1000 * 60  * 60 * 5# 1s * 60 * 60 = 1hr
                                data_correct = False

                    if next_release.astimezone(self.tz) < now:
                        indicator_updates = mb_up.available_updates()
                    else:
                        # No updates, wait until next release time until checking again.
                        indicator_updates = []
                        time_diff = next_release - now
                        error_margin_min = 15 # Error margin in minutes
                        error_margin = 1000 * 60  * error_margin_min
                        if data_correct:
                            self.timeout = time_diff.total_seconds() * 1000 + error_margin
                        else:
                        	if (time_diff.total_seconds() * 1000 + error_margin) < self.timeout:
                        		self.timeout = time_diff.total_seconds() * 1000 + error_margin

                    if len(indicator_updates) > 0:
                        logging.info("Updates found for: %s", str(indicator_updates))
                        c = win32com.client.Dispatch("Macrobond.Connection")
                        d = c.Database
                        all_series = d.FetchSeries(indicator_updates)
                        logging.info("Series fetched for indicators")
                        for num, indicator_key in enumerate(all_series):
                            ts = all_series[num]
                            releaseName = ts.Metadata.GetFirstValue("Release")
                            releaseEntity = d.FetchOneEntity(releaseName)
                            current_release = releaseEntity.Metadata.GetFirstValue("LastReleaseEventTime")
                            next_release = releaseEntity.Metadata.GetFirstValue("NextReleaseEventTime")
                            if not next_release:
                                next_release = pywintypes.Time(0).replace(year=1900, month=1, day=1)
                            if ts:
                                logging.info("Uploading data for indicator %s", str(indicator_key))
                                mb_up.upload_mb_data(ts, str(indicator_key),  current_release, next_release)
                            logging.info("Upload complete for indicator %s", str(indicator_key))
                        next_release = mb_up.next_release_date()[0]
                        time_diff = next_release - now
                        error_margin_min = 15 # Error margin in minutes
                        error_margin = 1000 * 60  * error_margin_min
                        if (time_diff.total_seconds() * 1000 + error_margin) < self.timeout:
                        		self.timeout = time_diff.total_seconds() * 1000 + error_margin

                        if len([indicator[0] for indicator in indicator_updates if indicator[0].find('usfcst') ]) > 0:
                            self.LaunchModelScript()
                            logging.info("Before email latest run is %s", str(mb_up.return_latest_run_id()))
                            self.indicatorChange(mb_up, indicator_updates)

                    else:
                        logging.info("No updates found, waiting for %s minutes", str(self.timeout / 60000))

                    logging.info("Next Release is: %s", datetime.datetime.strftime(mb_up.next_release_date()[0], '%Y-%m-%d %H:%M'))
                    logging.info("Next check will be: %s", datetime.datetime.strftime(now + datetime.timedelta(seconds = (self.timeout * 0.001)), '%Y-%m-%d %H:%M'))

                except:
                    self.sendErrorMail(str(traceback.format_exc()))
                    logging.info("Connection failed with: %s", traceback.format_exc())
                    servicemanager.LogErrorMsg(traceback.format_exc())
                    pass
Exemple #12
0
def changeFileCreateTime(file1, ctime):
    handle = win32file.CreateFile(file1, win32file.GENERIC_WRITE, 0, None,
                                  win32file.OPEN_EXISTING, 0, 0)
    PyTime = pywintypes.Time(nfile3)
    win32file.SetFileTime(handle, PyTime)