本文整理汇总了Python中pycalendar.icalendar.calendar.Calendar.addComponent方法的典型用法代码示例。如果您正苦于以下问题:Python Calendar.addComponent方法的具体用法?Python Calendar.addComponent怎么用?Python Calendar.addComponent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pycalendar.icalendar.calendar.Calendar
的用法示例。
在下文中一共展示了Calendar.addComponent方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getTimezone
# 需要导入模块: from pycalendar.icalendar.calendar import Calendar [as 别名]
# 或者: from pycalendar.icalendar.calendar.Calendar import addComponent [as 别名]
def getTimezone(self, tzid):
"""
Generate a PyCalendar containing the requested timezone.
"""
# We will just use our existing TimezoneCache here
calendar = Calendar()
try:
vtz = readVTZ(tzid)
calendar.addComponent(vtz.getComponents()[0].duplicate())
except TimezoneException:
# Check if an alias exists and create data for that
if tzid in self.aliases:
try:
vtz = readVTZ(self.aliases[tzid])
except TimezoneException:
log.error("Failed to find timezone data for alias: %s" % (tzid,))
return None
else:
vtz = vtz.duplicate()
vtz.getComponents()[0].getProperties("TZID")[0].setValue(tzid)
addVTZ(tzid, vtz)
calendar.addComponent(vtz.getComponents()[0].duplicate())
else:
log.error("Failed to find timezone data for: %s" % (tzid,))
return None
return calendar
示例2: generateZoneinfoFiles
# 需要导入模块: from pycalendar.icalendar.calendar import Calendar [as 别名]
# 或者: from pycalendar.icalendar.calendar.Calendar import addComponent [as 别名]
def generateZoneinfoFiles(self, outputdir, minYear, maxYear=2018, links=True, windowsAliases=None, filterzones=None):
# Empty current directory
try:
for root, dirs, files in os.walk(outputdir, topdown=False):
for name in files:
os.remove(os.path.join(root, name))
for name in dirs:
os.rmdir(os.path.join(root, name))
except OSError:
pass
for zone in self.zones.itervalues():
if filterzones and zone.name not in filterzones:
continue
cal = Calendar()
vtz = zone.vtimezone(cal, self.rules, minYear, maxYear)
cal.addComponent(vtz)
icsdata = cal.getText()
fpath = os.path.join(outputdir, zone.name + ".ics")
if not os.path.exists(os.path.dirname(fpath)):
os.makedirs(os.path.dirname(fpath))
with open(fpath, "w") as f:
f.write(icsdata)
if self.verbose:
print("Write path: %s" % (fpath,))
if links:
if windowsAliases is not None:
self.parseWindowsAliases(windowsAliases)
link_list = []
for linkTo, linkFrom in sorted(self.links.iteritems(), key=lambda x: x[0]):
# Check for existing output file
fromPath = os.path.join(outputdir, linkFrom + ".ics")
if not os.path.exists(fromPath):
print("Missing link from: %s to %s" % (linkFrom, linkTo,))
continue
with open(fromPath) as f:
icsdata = f.read()
icsdata = icsdata.replace(linkFrom, linkTo)
toPath = os.path.join(outputdir, linkTo + ".ics")
if not os.path.exists(os.path.dirname(toPath)):
os.makedirs(os.path.dirname(toPath))
with open(toPath, "w") as f:
f.write(icsdata)
if self.verbose:
print("Write link: %s" % (linkTo,))
link_list.append("%s\t%s" % (linkTo, linkFrom,))
# Generate link mapping file
linkPath = os.path.join(outputdir, "links.txt")
with open(linkPath, "w") as f:
f.write("\n".join(link_list))
示例3: getTimezoneInCalendar
# 需要导入模块: from pycalendar.icalendar.calendar import Calendar [as 别名]
# 或者: from pycalendar.icalendar.calendar.Calendar import addComponent [as 别名]
def getTimezoneInCalendar(tzid):
"""
Return a VTIMEZONE inside a valid VCALENDAR
"""
tz = TimezoneDatabase.getTimezone(tzid)
if tz is not None:
from pycalendar.icalendar.calendar import Calendar
cal = Calendar()
cal.addComponent(tz.duplicate(cal))
return cal
else:
return None
示例4: vtimezones
# 需要导入模块: from pycalendar.icalendar.calendar import Calendar [as 别名]
# 或者: from pycalendar.icalendar.calendar.Calendar import addComponent [as 别名]
def vtimezones(self, minYear, maxYear=2018, filterzones=None):
"""
Generate iCalendar data for all VTIMEZONEs or just those specified
"""
cal = Calendar()
for zone in self.zones.itervalues():
if filterzones and zone.name not in filterzones:
continue
vtz = zone.vtimezone(cal, self.rules, minYear, maxYear)
cal.addComponent(vtz)
return cal.getText()
示例5: TimezoneDatabase
# 需要导入模块: from pycalendar.icalendar.calendar import Calendar [as 别名]
# 或者: from pycalendar.icalendar.calendar.Calendar import addComponent [as 别名]
class TimezoneDatabase(object):
"""
On demand timezone database cache. This scans a TZdb directory for .ics files matching a
TZID and caches the component data in a calendar from whence the actual component is returned.
"""
sTimezoneDatabase = None
@staticmethod
def createTimezoneDatabase(dbpath):
TimezoneDatabase.sTimezoneDatabase = TimezoneDatabase()
TimezoneDatabase.sTimezoneDatabase.setPath(dbpath)
@staticmethod
def clearTimezoneDatabase():
if TimezoneDatabase.sTimezoneDatabase is not None:
TimezoneDatabase.sTimezoneDatabase.clear()
def __init__(self):
from pycalendar.icalendar.calendar import Calendar
self.dbpath = None
self.calendar = Calendar()
self.tzcache = {}
self.stdtzcache = set()
def setPath(self, dbpath):
self.dbpath = dbpath
def clear(self):
from pycalendar.icalendar.calendar import Calendar
self.calendar = Calendar()
self.tzcache.clear()
self.stdtzcache.clear()
@staticmethod
def getTimezoneDatabase():
if TimezoneDatabase.sTimezoneDatabase is None:
TimezoneDatabase.sTimezoneDatabase = TimezoneDatabase()
return TimezoneDatabase.sTimezoneDatabase
@staticmethod
def getTimezone(tzid):
return TimezoneDatabase.getTimezoneDatabase()._getTimezone(tzid)
@staticmethod
def getTimezoneInCalendar(tzid):
"""
Return a VTIMEZONE inside a valid VCALENDAR
"""
tz = TimezoneDatabase.getTimezone(tzid)
if tz is not None:
from pycalendar.icalendar.calendar import Calendar
cal = Calendar()
cal.addComponent(tz.duplicate(cal))
return cal
else:
return None
@staticmethod
def getTimezoneOffsetSeconds(tzid, dt, relative_to_utc=False):
# Cache it first
tz = TimezoneDatabase.getTimezone(tzid)
if tz is not None:
return tz.getTimezoneOffsetSeconds(dt, relative_to_utc)
else:
return 0
@staticmethod
def getTimezoneDescriptor(tzid, dt):
# Cache it first
tz = TimezoneDatabase.getTimezone(tzid)
if tz is not None:
return tz.getTimezoneDescriptor(dt)
else:
return ""
@staticmethod
def isStandardTimezone(tzid):
return TimezoneDatabase.getTimezoneDatabase()._isStandardTimezone(tzid)
def cacheTimezone(self, tzid):
"""
Load the specified timezone identifier's timezone data from a file and parse it
into the L{Calendar} used to store timezones used by this object.
@param tzid: the timezone identifier to load
@type tzid: L{str}
#.........这里部分代码省略.........