def load_drawing_from_file(file, filename = '', doc_class = None): # Note: the doc_class argument is only here for plugin interface # compatibility with 0.7 (especiall e.g. gziploader) line = file.readline() # XXX ugly hack for riff-based files, e.g. Corel's CMX. The length # might contain newline characters. if line[:4] == 'RIFF' and len(line) < 12: line = line + file.read(12 - len(line)) #print line for info in plugins.import_plugins: match = info.rx_magic.match(line) if match: loader = info(file, filename, match) try: if do_profile: import profile warn(INTERNAL, 'profiling...') prof = profile.Profile() prof.runctx('loader.Load()', globals(), locals()) prof.dump_stats(os.path.join(info.dir, info.module_name + '.prof')) warn(INTERNAL, 'profiling... (done)') doc = loader.object else: #t = time.clock() doc = loader.Load() #print 'load in', time.clock() - t, 'sec.' messages = loader.Messages() if messages: doc.meta.load_messages = messages return doc finally: info.UnloadPlugin() else: raise SketchLoadError(_("unrecognised file type"))
def _search_dir(dir, recurse, package = 'Sketch.Plugins'): try: files = os.listdir(dir) except os.error, value: warn(USER, _("Cannot list directory %(filename)s\n%(message)s"), filename = dir, message = value[1]) return
def _search_dir(dir, recurse, package='Sketch.Plugins'): try: files = os.listdir(dir) except os.error, value: warn(USER, _("Cannot list directory %(filename)s\n%(message)s"), filename=dir, message=value[1]) return
def groupByLambda(func, items): """Performs a grouping of the items by lambda value.""" import warn warn.warn(u'groupByLambda() is deprecated') groups = {} for item in items: keyValue = func(item) itemList = groups.get(keyValue, []) itemList.append(item) groups[keyValue] = itemList return groups
def group_by_lambda(func, items): """Performs a grouping of the items by lambda value.""" import warn warn.warn(u'group_by_lambda() is deprecated') groups = {} for item in items: key_value = func(item) item_list = groups.get(key_value, []) item_list.append(item) groups[key_value] = item_list return groups
def main(): # 基础url,根据基金代码拼成最终的url,例如 baseUrl = 'http://fund.eastmoney.com/' # excel文件保存路径,每天的文件按日期拼接成最终的路径,例如’fund数据(2021-04-22).xls‘ savePath = 'fund数据' print('爬虫启动!!!') print('#' * 66) # 计时 old = datetime.datetime.now() # 获取数据列表 dataList = getData(baseUrl) new = datetime.datetime.now() print('#' * 66) print('爬取完毕,共耗时%s秒\n' % (new - old).seconds) # 保存数据到excel print('保存数据中......') saveData(savePath, dataList) print('保存完毕,请查看当前文件夹下的今日数据......\n') # 生成预警基金列表 print('生成预警基金列表中......') warnList = warn() print('生成完毕,将自动发送邮件,请注意查收!!!') print('#' * 66) # 自动发送邮件 if len(warnList) != 0: auto_email(warnList)
def Undo(info): # execute a single undoinfo func = info[0] if type(func) == StringType: text = func func = info[1] args = info[2:] else: args = info[1:] text = None try: redo = apply(func, args) if text is not None and callable(redo[0]): return (text,) + redo else: return redo except: warn(INTERNAL, "Exception in undo:\ninfo: %s\nfunc: %s\nargs: %s", info, func, args) warn_tb(INTERNAL)
def Undo(info): # execute a single undoinfo func = info[0] if type(func) == StringType: text = func func = info[1] args = info[2:] else: args = info[1:] text = None try: redo = apply(func, args) if text is not None and callable(redo[0]): return (text, ) + redo else: return redo except: warn(INTERNAL, 'Exception in undo:\ninfo: %s\nfunc: %s\nargs: %s', info, func, args) warn_tb(INTERNAL)
def main(): # 功能选择 print("+---------------请选择操作:------------+\n") print("1.--------入库--------\n") print("2.--------出库--------\n") print("3.--------查询--------\n") print("4.--------统计--------\n") warn.warn() str = int(input("\n请输入:")) #功能实现 if str == 1: store.store() elif str == 2: reduce.reduce() elif str == 3: query.query() elif str == 4: print("------------统计功能---------\n") print("1.----------库元件总价值统计---------------\n") print("2.----------每月出库元件总价值统计---------\n") print("3.----------各类元件本月消耗量-------------\n") first_value = int(input("请选择统计类:")) statistics.statistics(first_value)
def warn(bot, update): try: messagereplied = update.message.reply_to_message.from_user.id except: bot.send_message(chat_id=chatid(update), text='please reply to the user you want to kick') return if update.message.from_user.username.endswith('bot'): bot.send_message(chat_id=chatid(update), text='bots are not bannable by bots') return if admin.isadmin(id(update)): warning = warnmodule.warn(update.message.reply_to_message.from_user.id) status = warnmodule.get_status(update.message.reply_to_message.from_user.id) if status > 3: bot.send_message(chatid(update), 'User has been warned more than three times, beggining kick progress.') kick(bot, update) warn.unwarn(update.message.reply_to_message.from_user.id) else: bot.send_message(chatid(update), 'warned successfully. User has now: {0} out of 4 warns.'.format(status)) else: bot.send_message(chat_id=chatid(update), text='you have to be admin to perform this command')
lib_pkg = create_packages(package + '.Lib') lib_pkg.__path__.append(filename) elif recurse: # an ordinary directory and we should recurse into it to # find more modules, so do that. _search_dir(filename, recurse - 1, package + '.' + file) elif filename[-3:] == '.py': try: module_name = os.path.splitext(os.path.basename(filename))[0] vars = {'_': _} # hack cfg = extract_cfg(filename) exec cfg in config_types, vars infoclass = vars.get('type') if infoclass is None: warn(USER, _("No plugin-type information in %(filename)s"), filename=filename) else: del vars['type'] del vars['_'] info = apply(infoclass, (module_name, dir), vars) info.package = package except: warn_tb(INTERNAL, 'In config file %s', filename) warn(USER, _("can't read configuration information from " "%(filename)s"), filename=filename) def load_plugin_configuration(): #path):
def parse_header(file, info): # Parse the header section of FILE and store the information found # in the INFO object which is assumed to be an instance of EpsInfo. # # This works for the %%Trailer section as well so that parsing the # beginning (until %%EndComments) and end (from %%Trailer) if # necessary with the same INFO object should get all information # available. line = file.readline() last_key = '' while line: match = rx_dsccomment.match(line) if match: key = match.group(1) value = strip(line[match.end(0):]) if key == 'EndComments' or key == 'EOF': break if key == '+': key = last_key else: last_key = '' if key == 'BoundingBox': if value != ATEND: # the bounding box should be given in UINTs # but may also (incorrectly) be float. info.BoundingBox = tuple(map(atof, split(value))) else: info.atend = 1 elif key == 'DocumentNeededResources': if value != ATEND: if value: [type, value] = split(value, None, 1) if type == 'font': info.NeedResources(type, split(value)) else: # XXX: might occasionally be interesting for the # user warn(INTERNAL, 'needed resource %s %s ignored', type, value) else: info.atend = 1 elif key == 'DocumentNeededFonts': if value != ATEND: info.NeedResources('font', split(value)) else: info.atend = 1 elif key == 'DocumentSuppliedResources': if value != ATEND: if value: [type, value] = split(value, None, 1) if type == 'font': info.NeedResources(type, split(value)) else: # XXX: might occasionally be interesting for the # user warn(INTERNAL, 'supplied resource %s %s ignored', type, value) else: info.atend = 1 else: setattr(info, key, value) # last_key = key else: # the header comments end at a line not beginning with %X, # where X is a printable character not in SPACE, TAB, NL # XXX: It is probably wrong to do this in the %%Trailer if line[0] != '%': break if len(line) == 1 or line[1] not in endcommentchars: break line = file.readline()
# Lib. lib_pkg = create_packages(package + '.Lib') lib_pkg.__path__.append(filename) elif recurse: # an ordinary directory and we should recurse into it to # find more modules, so do that. _search_dir(filename, recurse - 1, package + '.' + file) elif filename[-3:] == '.py': try: module_name = os.path.splitext(os.path.basename(filename))[0] vars = {'_':_} # hack cfg = extract_cfg(filename) exec cfg in config_types, vars infoclass = vars.get('type') if infoclass is None: warn(USER, _("No plugin-type information in %(filename)s"), filename = filename) else: del vars['type'] del vars['_'] info = apply(infoclass, (module_name, dir), vars) info.package = package except: warn_tb(INTERNAL, 'In config file %s', filename) warn(USER, _("can't read configuration information from " "%(filename)s"), filename = filename) def load_plugin_configuration(): #path): if __debug__: import time start = time.clock()
def warn(self, i): self.wdialog = warn.warn(i) self.wdialog.exec_()
def warn(bot, update): from warn import warn warn(bot, update)
#! /usr/bin/env python import warn import archive if __name__ == "__main__": warn.warn() archive.archive()