如何在脚本中添加身份验证步骤?

问题描述

我有一个脚本,在该脚本下,我希望安排每天通过SQL Server运行该脚本并将日历事件存储到数据库中,但是问题是我需要打开Outlook才能运行此脚本,我该如何在脚本中添加我的凭据,这样我就不必打开Outlook并在不打开Outlook的情况下运行脚本?谢谢

import win32com.client,datetime
from datetime import date
from dateutil.parser import *
import calendar
import pandas as pd
import pyodbc

Outlook = win32com.client.Dispatch("Outlook.Application")
ns = Outlook.GetNamespace("MAPI")

Item = Outlook.CreateItem ( 1 )
Recip = Item.Recipients.Add ( 'Corporate Master Calendar' )

appts = ns.GetSharedDefaultFolder(Recip,9).Items
appts.Sort("[Start]")
appts.IncludeRecurrences = "False"

eoy=date(date.today().year,12,31)
eoy=eoy.strftime("%m/%d/%Y")
begin = date.today()
begin = begin.strftime("%m/%d/%Y")

appts = appts.Restrict("[Start] >= '" +begin+ "' AND [Start] <= '" +eoy+ "'")

apptDict = {}
item = 0
for indx,a in enumerate(appts):
        organizer = str(a.Organizer)
        start = a.Start
        end = a.End
        subject = str(a.Subject)
        location = str(a.Location)
        categories = str(a.Categories)
        body=str(a.Body)
        itemid=str(a.GlobalAppointmentId)
        lmt=str(a.LastModificationTime)
        apptDict[item] = {"GlobalAppointmentId": itemid,"Organizer": organizer,"Subject": subject,"Location": location,"Start": start,"End": end,"Body": body,"Categories": categories,"LMT":lmt}
        item = item + 1

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)