Example #1
0
    def __init__(self, session):

        cmd.Cmd.__init__(self)

        self.session = session
        self.prompt = 'weevely> '

        # Load all available modules
        self._load_modules()

        # Load history file
        self._load_history()

        # Set a nice intro
        self.intro = template.Template(
            messages.terminal.welcome_to_s
        ).render(
            path = self.session.get('path'),
            conn_info = session.get_connection_info(),
            version = messages.version,
            default_shell = self.session.get('default_shell')
        )

        # Set default encoding utf8
        reload(sys)
        sys.setdefaultencoding('utf8')
Example #2
0
File: vtMain.py Project: flatM/vnpy
def main():
    """主程序入口"""
    # 设置底部任务栏图标,win7以下请注释掉
    if platform.uname() == 'Windows':
        ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('vn.py demo')  
    
    # Reload sys, Set default encode to UTF8
    reload(sys)
    sys.setdefaultencoding('utf8')

    # 初始化Qt应用对象
    app = QtGui.QApplication(sys.argv)
    app.setWindowIcon(QtGui.QIcon('vnpy.ico'))
    app.setFont(BASIC_FONT)
    
    # 设置Qt的皮肤
    try:
        f = file("VT_setting.json")
        setting = json.load(f)    
        if setting['darkStyle']:
            import qdarkstyle
            app.setStyleSheet(qdarkstyle.load_stylesheet(pyside=False))
    except:
        pass
    
    # 初始化主引擎和主窗口对象
    mainEngine = MainEngine()
    mainWindow = MainWindow(mainEngine, mainEngine.eventEngine)
    mainWindow.showMaximized()
    
    # 在主线程中启动Qt事件循环
    sys.exit(app.exec_())
Example #3
0
 def __init__(self):
     reload(sys)
     sys.setdefaultencoding('UTF-8')
     self.datatype = 'main'
     self.title = '网易云音乐'
     self.datalist = ['排行榜', '艺术家', '新碟上架', '精选歌单', '我的歌单', 'DJ节目', '打碟', '收藏', '搜索', '帮助']
     self.offset = 0
     self.index = 0
     self.presentsongs = []
     self.player = Player()
     self.ui = Ui()
     self.netease = NetEase()
     self.screen = curses.initscr()
     self.screen.keypad(1)
     self.step = STEP
     self.stack = []
     self.djstack = []
     self.userid = None
     self.username = None
     try:
         sfile = file(home + "/netease-musicbox/flavor.json",'r')
         data = json.loads(sfile.read())
         self.collection = data['collection']
         self.account = data['account']
         sfile.close()
     except:
         self.collection = []        
         self.account = {}
Example #4
0
def configure_locale():
    logger.debug("Before %s", locale.nl_langinfo(locale.CODESET))
    current_locale = locale.getlocale()

    if current_locale[1] is None:
        logger.debug("No locale currently set. Attempting to get default locale.")
        default_locale = locale.getdefaultlocale()

        if default_locale[1] is None:
            logger.debug("No default locale exists. Let's try loading from /etc/default/locale")
            if os.path.exists("/etc/default/locale"):
                config = ConfigObj('/etc/default/locale')
                lang = config.get('LANG')
                new_locale = lang
            else:
                logger.error("/etc/default/locale could not be found! Please run 'sudo update-locale' from command-line.")
                sys.exit(1)
        else:
            new_locale = default_locale

        logger.info("New locale set to: %s", locale.setlocale(locale.LC_ALL, new_locale))



    reload(sys)
    sys.setdefaultencoding("UTF-8")
    current_locale_encoding = locale.getlocale()[1].lower()
    logger.debug("sys default encoding %s", sys.getdefaultencoding())
    logger.debug("After %s", locale.nl_langinfo(locale.CODESET))

    if current_locale_encoding not in ['utf-8', 'utf8']:
        logger.error("Need a UTF-8 locale. Currently '%s'. Exiting..." % current_locale_encoding)
        sys.exit(1)
Example #5
0
    def test_astype_unicode(self):

        # GH7758
        # a bit of magic is required to set default encoding encoding to utf-8
        digits = string.digits
        test_series = [
            Series([digits * 10,
                    tm.rands(63),
                    tm.rands(64),
                    tm.rands(1000)]),
            Series([u('データーサイエンス、お前はもう死んでいる')]),
        ]

        former_encoding = None
        if not compat.PY3:
            # in python we can force the default encoding for this test
            former_encoding = sys.getdefaultencoding()
            reload(sys)  # noqa
            sys.setdefaultencoding("utf-8")
        if sys.getdefaultencoding() == "utf-8":
            test_series.append(Series([u('野菜食べないとやばい').encode("utf-8")]))
        for s in test_series:
            res = s.astype("unicode")
            expec = s.map(compat.text_type)
            assert_series_equal(res, expec)
        # restore the former encoding
        if former_encoding is not None and former_encoding != "utf-8":
            reload(sys)  # noqa
            sys.setdefaultencoding(former_encoding)
Example #6
0
def findMovieReviewers(movie_id, subUrl) :	
	print movie_id
	print subUrl
	reload(sys)
	sys.setdefaultencoding('utf-8')
	
	cj = cookielib.LWPCookieJar() 
	try: 
		cj.revert('douban.cookie') 
	except: 
		try :
			dou=douban() 
			username='******' 
			password='******' 
			domain='http://www.douban.com/' 
			origURL='http://www.douban.com/login' 
			dou.setinfo(username,password,domain,origURL) 
			dou.signin()  
		except : 
			return
	opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) 
	urllib2.install_opener(opener) 
	collectPage = urllib2.urlopen("http://movie.douban.com/subject/" + movie_id + "/reviews" + subUrl, timeout=20).read().encode('utf-8')
	soup = BeautifulSoup(collectPage, 'html.parser')

	#init db connection
	conn = MySQLdb.connect(host='localhost',user='******',passwd='root')
	curs = conn.cursor()
	conn.select_db('pydb')

	reviewsOfThisPage = soup.findAll("a", { "class" : "review-hd-avatar" })

	countReviews = len(reviewsOfThisPage)
	print countReviews

	for review in reviewsOfThisPage :
		reviewSoup = BeautifulSoup(str(review), 'html.parser')
		userId = reviewSoup.a["href"].split("/")[4]
		try :
			#insert data into db rowbyrow
			curs.execute('INSERT INTO users (user_id) VALUES (%s)', userId)
			print "rows affected " + str(curs.rowcount)
		except :
			print "error inserting, probably duplicate for userid : " + userId
			None

	try :
		foundSubUrl = soup.find("a", { "class" : "next" })['href']
	except :
		foundSubUrl = ""

	print foundSubUrl

	conn.commit()
	curs.close()
	conn.close()	

	if "" != foundSubUrl  and countReviews > 0 :
		time.sleep( 2 )
		findMovieReviewers(movie_id, foundSubUrl)
def _setEncoding():
	"""
	This definition sets the Application encoding.
	"""

	reload(sys)
	sys.setdefaultencoding("utf-8")
Example #8
0
def main():
    reload(sys)
    sys.setdefaultencoding('utf-8')
    if len(sys.argv) < 2:
        print __doc__
        sys.exit(0)
    FileFilter(sys.argv[1])
Example #9
0
	def getCurriculum(self, index_read_text, xnd, xqd):
		print("执行获取课表的动作")
		postData = {
			'__EVENTTARGET': 'xnd',
			'__EVENTARGUMENT': '',
			'__VIEWSTATE' : index_read_text.xpath('//input[@name="__VIEWSTATE"]/@value')[0],
			'xnd' : xnd,
			'xqd' : xqd
		}
		secondRequest = requests.post(self.Curriculum_URL, data=postData, headers=self.header)
		#print(secondRequest.text)
		#这里的xpath表达式中 /text()  莫名其妙的就取到了所有该节点下的全部内容,
		#包括<br>标签分割的内容,经测试发现,text()函数跟在/后面可行,如果不跟,
		#则用item去取,例如 h.text 是不能取得全部内容的,原因不明,继续查官方文档
		#2015-12-12:text()只能取到上一级标签下的全部内容, br可以忽略掉取,但再加一层标签,无法取到内部。
		h_list = etree.HTML(secondRequest.text).xpath("//table[@id='Table1']//tr[position()>2]//td[@align]/text()")
		i = 0
		print('xnd = '+xnd+'   xqd = '+xqd)
		xnxqd = xnd+','+xqd

		import sys
		reload(sys)
		sys.setdefaultencoding( "utf-8" )
		l = []
		for h in range(len(h_list)):
			if h_list[h].decode('utf-8')[0:3] in [u'周一第', u'周二第', u'周三第', u'周四第', u'周五第', u'周六第',u'周日第']:
				l.append(h_list[h-1])
				l.append(h_list[h])
				l.append(h_list[h+1])
				l.append(h_list[h+2])
				h = h+3
				#print(str(i)+" : "+h)
		s = '!'.join(l)
		self.myCollection.update({'stuId':self.stuNum}, {"$set":{xnxqd:s}}, upsert=True)
		return etree.HTML(secondRequest.text)
Example #10
0
    def __init__(self):
        reload(sys)
        sys.setdefaultencoding('UTF-8')
        self.data_type = 'main'
        # Title of the application
        self.title = '网易云音乐'
        # Main-menu list
        self.data_list = ['排行榜', '艺术家', '新碟上架', '精选歌单', '我的歌单', 'DJ节目', '打碟', '收藏', '搜索', '帮助']
        # Which page of the data_list is displayed (data_list may be displayed in multiple pages
        self.page_index = 0
        # The index of the current selected line
        self.current_line_index = 0
        self.present_songs = []
        self.player = Player()
        self.ui = Ui()
        self.netease = NetEase()
        self.screen = curses.initscr()
        self.screen.keypad(1)
        self.page_size = 10  # The number of lines that can be displayed on one page.
        self.stack = []
        self.dj_stack = []
        self.user_id = None
        self.user_name = None

        # Read in the collection and account in flavor.json
        try:
            config_file = file(Constant.conf_dir + "/flavor.json", 'r')
            data = json.loads(config_file.read())
            self.collection = data['collection']
            self.account = data['account']
            config_file.close()
        except:
            self.collection = []
            self.account = {}
Example #11
0
 def __init__(self):
     reload(sys)
     sys.setdefaultencoding("UTF-8")
     self.datatype = "main"
     self.title = "网易云音乐"
     self.datalist = ["排行榜", "艺术家", "新碟上架", "精选歌单", "我的歌单", "DJ节目", "打碟", "收藏", "搜索", "帮助"]
     self.offset = 0
     self.index = 0
     self.storage = Storage()
     self.storage.load()
     self.collection = self.storage.database["collections"][0]
     self.player = Player()
     self.ui = Ui()
     self.netease = NetEase()
     self.screen = curses.initscr()
     self.screen.keypad(1)
     self.step = 10
     self.stack = []
     self.djstack = []
     self.userid = None
     self.username = None
     self.resume_play = True
     signal.signal(signal.SIGWINCH, self.change_term)
     signal.signal(signal.SIGINT, self.send_kill)
     self.START = time.time()
Example #12
0
def main( argv ):
    reload( sys )
    sys.setdefaultencoding( 'utf-8' )
    parser = optparse.OptionParser( usage = '''python collect.py start|stop|restart [-c config.xml]''' )
    parser.add_option( "-c", "--config", action = "store", type = "string", dest = "confFile" )
    parser.add_option( "-a", "--alllog", action = "store_true", dest = "alllog" )
    parser.add_option( "-n", "--notimestamp", action = "store_true", dest = "notimestamp" )
    parser.add_option( "-d", "--date", action = "store", type = "string", dest = "date" , default = 0, help = "specify the date(date or number). eg: 2013-1-21 ,  1 refer to yesterday " )
    ( options, args ) = parser.parse_args( sys.argv[1:] )
    # multi collect process under same path
    if options.confFile == None:
        confFile = 'config.xml'
    else:
        confFile = options.confFile
    if confFile.endswith( '.xml' ):
        pidFile = confFile[0:-4] + '.pid'
        logFile = '%s.log' % confFile[0:-4]
    else:
        pidFile = confFile + '.pid'
        logFile = '%s.log' % confFile
    # start or stop
    if len( args ) == 1 and args[0] in ['start', 'stop', 'restart']:
        collect = Collect( os.path.abspath( confFile ), os.path.abspath( pidFile ), os.path.abspath( logFile ), options.alllog, options.date, options.notimestamp )
        if args[0] == 'start':
            collect.start()
        elif args[0] == 'stop':
            collect.stop()
        else:
            collect.restart()
    else:
        parser.print_help()
        exit( -1 )
Example #13
0
    def __init__(self,parent=None):  
        super(TestDialog,self).__init__(parent) 
        reload(sys)
        sys.setdefaultencoding('utf-8')
        #从网络获取最新数据
        gouke = gettheme_add.guoketheme('http://www.guokr.com/site/all','/site/all','http://www.guokr.com/site/all')
        gouke.getthemelist()
        document = getdocument.dodocument()
        document.inserthead2()
        
        
        self.pageid = 0
        self.query = False#是否点击查询按钮
        self.queryid = 0
        self.mainUi=myrssmain.Ui_MainWindow()
        self.mainUi.setupUi(self) 
        self.db = model.myrss()
        self.themecount = self.db.selectthemecount()[0]-1
        #初始化时间空间数据
        self.initaddtime = self.db.selectinittime()
        self.starttime = datetime.datetime.strptime(self.initaddtime[0][:10],'%Y-%m-%d')
        self.endtime = datetime.datetime.strptime(self.initaddtime[1][:10],'%Y-%m-%d')
#        print type(self.starttime)
        self.mainUi.starttime.setDate(self.starttime)
        self.mainUi.endtime.setDate(self.endtime)
        #加载数据
        self.loadtable()
        #界面操作
        self.mainUi.prepagebut.clicked.connect(self.prepage)
        self.mainUi.nextpagebut.clicked.connect(self.nextpage)
        self.mainUi.startpagebut.clicked.connect(self.startpage)
        self.mainUi.endpagebut.clicked.connect(self.endpage)
        self.mainUi.clearbut.clicked.connect(self.resetcont)
        self.mainUi.selectbut.clicked.connect(self.querycont)
Example #14
0
	def get_movie_page(self, response):
		reload(sys)
		sys.setdefaultencoding("utf-8")
		open('Pages/CrawledNextPages.log', 'ab').write(response.url + '\n')
		sel = Selector(response)
		next_pages = sel.xpath('//*[@class="pages"]/a/@href').extract()
		#if _DEBUG == True: 
		#		import pdb 
		#		pdb.set_trace() 
		#print next_pages
		item_pages = sel.xpath('//*[@class="folder"]/a/@href').extract()
		#open('Pages/Subpages.log', 'ab').write('\n'.join(next_pages))
		for next_page in next_pages:
		#	print self.get_complete_url(next_page)
		#	yield scrapy.http.Request(self.get_complete_url(next_page), callback=self.get_movie_page)
		#	if _DEBUG == True: 
		#		import pdb 
		#		pdb.set_trace() 
			open('Pages/NextPages.log', 'ab').write(response.url + '\n')
			yield self.make_requests_from_url(self.get_complete_url(next_page))
		for item_page in item_pages:
			item_page = self.get_complete_url(item_page)
			print item_page
			open('Pages/ItemPages.log', 'ab').write(item_page + '\n')
			yield scrapy.http.Request(item_page, callback=self.get_movie_item)
Example #15
0
def setDefaultEncoding():
    if hasattr(sys, 'setdefaultencoding'):
        sys.setdefaultencoding(DEFAULT_ENCODING)
        del sys.setdefaultencoding
        import logging
        configLog = logging.getLogger('Config')
        configLog.info('Default encoding set to %s', sys.getdefaultencoding())
Example #16
0
    def call(self, method, request):
        ''' Call the webservice method with the validated request content

        Args:
            method (str): Name of the method available at the webservice
            request (RequestObject): Object containing all the info needed

        Returns:
            dict: Result of the service call
        '''
        service_method = getattr(self.client.service, method, None)

        req_type = 'Request' + method[0].upper() + method[1:]
        req_instance = request.__class__.__name__

        if req_type != req_instance:
            raise WebserviceError(
                'Request must be an instance of {0}, given {1}'.format(
                    req_type,
                    req_instance
                 )
            )

        import sys
        if sys.version_info <= (3, 0):
            reload(sys)
            sys.setdefaultencoding('utf-8')

        try:
            return service_method(**request)
        except ValueError as e:
            raise WebserviceError(e)
Example #17
0
    def __init__(self, arg=None):
        """Application setup"""
        # encoding=utf8
        reload(sys)
        sys.setdefaultencoding('utf8')

        super(Application, self).__init__()
        global settings
        self.settings = {
            'debug': 1,
            'rootdir': '',
            'datadir': '',
            'data_folders':['Charachters', 'Houses', 'Culture', 'History'],
            'data_types': ['info', 'text', 'nlp'],
            'storage_folder': {},
        }

        # Get config options
        try:
            # guess installation folder
            _cur_path =  os.path.dirname(__file__)
            self.settings['rootdir'] = os.path.realpath(_cur_path+'/../..')
            # assign data dir
            self.settings['datadir'] =  '/'.join([self.settings['rootdir'],'Data'])
            if not os.path.exists(self.settings['datadir']):
                os.makedirs(self.settings['datadir'])

            for dir_path in [self.settings['rootdir'], self.settings['datadir']]:
                if not dir_path or not os.path.isdir(dir_path):
                    raise RootDirException()
        except Exception, e:
            traceback.print_exc()
Example #18
0
def _main():
    import sys
    reload(sys)
    sys.setdefaultencoding('utf8')

    _api_path = os.path.dirname(os.path.abspath(__file__)) + os.path.sep + ".." + os.path.sep + "api"
    _mmdb = "GeoLite2-City.mmdb"
    _mmdb = _api_path + os.path.sep + "geolite2" + os.path.sep + _mmdb
    
    if not os.path.exists(_mmdb):
        logging.error("no geolite2 mmdb, run scripts/download_geolite2.sh to download and restart api.")
        sys.exit()
        
    tornado.options.parse_command_line()
    
    _app = ApiApp()
    _app.geoip_reader = database.Reader(_mmdb)
        
    _http_server = tornado.httpserver.HTTPServer(_app)
    _http_server.listen(tornado.options.options.port)

    logging.info("Starting API servcie.")
    tornado.ioloop.IOLoop.instance().start()
    
    return
Example #19
0
 def dotask(self):
     self.cmd = 'ping'
     if sys.platform == "win32":
         self.cmd += ' -n 3 '
     else:
         self.cmd += ' -c 3 '
     self.cmd += self.host
     # os.popen(self.cmd, 'r', self.result)
     print "default coding type: {0}".format(sys.getdefaultencoding())
     reload(sys)
     sys.setdefaultencoding('utf-8')
     args = shlex.split(self.cmd)
     p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     (tmpoutput, tmpouterr) = p.communicate()
     self.retcode = p.returncode
     self.output = "".join(tmpoutput)
     self.outerr = "".join(tmpouterr)
     print "return code: %d" % self.retcode
     print "stdout:"
     if self.output:
         if not isinstance(self.output, unicode):
             self.output = self.output.decode(chardet.detect(self.output)['encoding'])
         print self.output
     print "stderr:"
     if self.outerr:
         if not isinstance(self.outerr, unicode):
             self.outerr = self.outerr.decode(chardet.detect(self.outerr)['encoding'])
         print self.outerr
     '''
Example #20
0
    def __init__(self, name=None, description=None, epilog=None, debug_flag=True):
        self.db = ConfigDB()
        self.name = os.path.basename(sys.argv[0])

        reload(sys)
        sys.setdefaultencoding('utf-8')

        setproctitle('%s %s' % (self.name, ' '.join(sys.argv[1:])))
        signal.signal(signal.SIGINT, self.SIGINT)

        if name is None:
            name = self.name

        self.logger = SoundforestLogger()
        self.log = self.logger.default_stream

        self.parser = argparse.ArgumentParser(
            prog=name,
            description=description,
            epilog=epilog,
            add_help=True,
            conflict_handler='resolve',
        )
        self.subcommand_parser = None
        self.subcommands = None

        if debug_flag:
            self.parser.add_argument('--debug', action='store_true', help='Show debug messages')
Example #21
0
 def handle(self, *args, **options):
     reload(sys)
     sys.setdefaultencoding('iso-8859-1')
     
     path = options.get('taxo_file')
     
     if path == None:
         raise CommandError('You need to provide the taxonomy file path --taxo-file or -f')
 
     f = open(path, 'rw')
     
     
     
     #first delete all nodes
     Node.objects.all().delete()
     
     taxonomy = pickle.load(f)
     
     msni = MySQLNodeImporter()
     for i in taxonomy:
         count = 0
         while count < 3 :
             try:
                 msni.importNode(taxonomy[i])
                 break
             except:
                 count += 1 
                 Command.logger.error('could not import :' . taxonomy[i])
         if count == 3 :
             Command.logger.warning('skipping node '  . taxonomy[i])
Example #22
0
def main():
    reload(sys)
    sys.setdefaultencoding('utf-8')
    
    # 创建文档对象
    document = Document('e:/docs/demo2.docx')
    
    # 读取文档中所有的段落列表
    ps = document.paragraphs
    # 每个段落有两个属性:style和text
    ps_detail = [(x.text,x.style.name) for x in ps]
    with open('out.tmp','w+') as fout:
        fout.write('')
    # 读取段落并写入一个文件
    with open('out.tmp','a+') as fout:
        for p in ps_detail:
            fout.write(p[0] + '\t' + p[1] + '\n\n')
    
    # 读取文档中的所有段落的列表
    tables = document.tables
    # 遍历table,并将所有单元格内容写入文件中
    with open('out.tmp','a+') as fout:
        for table in tables:
            for row in table.rows:
                for cell in row.cells:
                    fout.write(cell.text + '\t')
                fout.write('\n')
def main(argv):
	reload(sys);
	sys.setdefaultencoding('utf-8');
	
	#타겟 준비
	targets = argv[1:]
	
	#알림 메시지 초기화
	Notify.init("make_comic_book")
	title = u'그림책 만들기'
	
	if not targets:
		msg = u'대상을 선택해 주세요!'
		Notify.Notification.new(title, msg, '').show()
		sys.exit(1)
	
	#변환
	for target in targets:
		try:
			cbz = MakeCbz().make(target, u'.')
		except Exception, err:
			Notify.Notification.new(title, unicode(err), '').show()
			raise SystemExit()
			
		ufp.trashPut(target)
		
		#메시지 작성
		msg = u"<b>%(target)s</b>를 <b>%(cbz)s</b>로 묶었습니다." % locals()
		
		#알림 메시지 보이기
		Notify.Notification.new(title, msg, '').show()
Example #24
0
 def __init__(self):
     sheet = Sheets('1mKAsY92nA3I6PhTkNd9aLIY8_SZMXERr2wg5WTYMk34', 'client_secret.json',
                    'FinancialData')
     self.last_id = sheet.get_last_id()
     sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
     reload(sys)
     sys.setdefaultencoding('utf-8')
Example #25
0
def __enableDefaultEncoding():
    import sys

    try:
        sys.setdefaultencoding("utf8")
    except LookupError:
        pass
Example #26
0
 def parse(self,response):
     reload(sys)
     sys.setdefaultencoding('utf-8')
     for i in range(95000,99318):
         url = "https://www.dy2018.com/i/" + str(i) + ".html"
         print str(i) + '...open'
         yield scrapy.spiders.Request(url=url, callback=self.parse_do)
Example #27
0
    def __init__(self, irc):
        self.__parent = super(Mantis, self)
        self.__parent.__init__(irc)

        self.saidBugs = ircutils.IrcDict()
        sayTimeout = self.registryValue('bugSnarferTimeout')
        for k in irc.state.channels.keys():
            self.saidBugs[k] = TimeoutQueue(sayTimeout)

        self.urlbase = self.registryValue('urlbase')
        self.privateurlbase = self.registryValue('privateurlbase')

        if self.privateurlbase != "":
            serviceUrl = self.privateurlbase + '/api/soap/mantisconnect.php'
        else:
            serviceUrl = self.urlbase + '/api/soap/mantisconnect.php'

        self.server = SOAPProxy(serviceUrl)._ns(namespace)
        self.username = self.registryValue('username')
        self.password = self.registryValue('password')
        self.oldperiodic = self.registryValue('bugPeriodicCheck')
        self.irc = irc
        self.lastBug = 0

        bugPeriodicCheck = self.oldperiodic
        if bugPeriodicCheck > 0:
            schedule.addPeriodicEvent(self._bugPeriodicCheck, bugPeriodicCheck, name=self.name())

        reload(sys)
        sys.setdefaultencoding('utf-8')
Example #28
0
def set_utf8_default_encoding():
    if sys.getdefaultencoding() in ['utf-8', 'UTF-8','cp65001','CP65001']:
        return

    # Regenerate setdefaultencoding.
    reload(sys)
    sys.setdefaultencoding('utf-8')

    for attr in dir(locale):
        if attr[0:3] != 'LC_':
            continue
        aref = getattr(locale, attr)
        try:
            locale.setlocale(aref, '')
        except locale.Error:
            continue
        try:
            lang = locale.getlocale(aref)[0]
        except (TypeError, ValueError):
            continue
        if lang:
            try:
                locale.setlocale(aref, (lang, 'UTF-8'))
            except locale.Error:
                os.environ[attr] = lang + '.UTF-8'
    try:
        locale.setlocale(locale.LC_ALL, '')
    except locale.Error:
        pass
    return
Example #29
0
    def get(self):
        # type = self.check_oper_right_custom_right(self._rightKey, self._exportUserKey)
        # if type == False:
        #     self.redirect(config.SOCRightConfig['siteDomain']+'Admin/NotRight')
        #     return

        import sys
        reload(sys)                        
        sys.setdefaultencoding('utf-8')    
        ps = self.get_page_config(title = '导出角色用户列表Excel')

        role = {}
        role['id'] = int(self.get_arg('id', '0'))
        role = role_logic.query_one(id = role['id'])
        ps['userName'] = self.get_arg('userName', '')        
        ps['page'] = int(self.get_arg('page', '1'))
        ps['pagedata'] = user_logic.query_page_by_roleid(roleID = role['id'], userName = ps['userName'], page = 1, size = 99999)

        users = ps['pagedata']['data']

        #生成excel文件
        info = u'''<table><tr><td>用户ID</td><td>用户名</td><td>姓名</td><td>部门名称</td><td>角色ID</td><td>角色名</td></tr>'''

        for user in users:
            u = u'''<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>''' % (str(user['id']), user['name'], user['realName'], 
                        user['departmentName'], role['id'], role['name'] )
            info = info + u
        info = info + u'</table>'
        fileName = config.SOCRightConfig['exportUserPath'] + str_helper.get_now_datestr() +'_'+ str_helper.get_uuid() + '.xls'

        path = config.SOCRightConfig['realPath'] + fileName
        file_object = open(path, 'w')
        file_object.write(info)
        file_object.close( )    
        self.redirect(config.SOCRightConfig['siteDomain']+fileName)
Example #30
0
 def export_content(self,filename):
     #print pymongo.version
     reload(sys)
     sys.setdefaultencoding("utf-8")
     db_name         = self.db.db_name
     mng_client      = pymongo.MongoClient(self.db.host, int(self.db.port))
     mng_db          = mng_client[db_name]                                                          # Replace mongo db name
     self.log.debug(mng_db.authenticate(self.db.username, self.db.password,mechanism='SCRAM-SHA-1'))
     collection_name = self.db.collection_name                                                      # Replace mongo db collection name
     db_cm           = mng_db[collection_name]
     self.log.debug(db_cm.find())
     #############################
     #############################
     #############################
     #self.log.debug(reduce(lambda all_keys, rec_keys: all_keys | set(rec_keys), map(lambda d: d.keys(), db_cm.find()), set()))
     try:
         doc=db_cm.find_one();
         self.MONGO_FIELDS=[]
         for key in doc :
             self.MONGO_FIELDS.append(key);
         cursor          = db_cm.find({},{'_id':0})   
         with open(filename, 'w+') as fp:
             fields = self.MONGO_FIELDS
             writer = csv.DictWriter(fp, fieldnames=fields,lineterminator = '\n')
             writer.writeheader()
             for r in cursor:
                 print r
                 writer.writerow(str(r).encode("utf-8"))
             mng_client.close()
     except Exception as ex:
         self.log.debug("Failed to obtain the collection from DataBase")
         traceback.print_exc()
         mng_client.close()
def genReport(fortifyXmlFileBaseDir, fortifyXmlFileNewDir,
              fortifyRptOutputDir):

    if not os.path.exists(fortifyXmlFileBaseDir) and not os.path.exists(
            fortifyXmlFileNewDir):
        print "Warning: fortifyXmlFileBaseDir and fortifyXmlFileNewDir not exist."
        # return 1

    if not os.path.exists(fortifyRptOutputDir):
        os.system("mkdir -p " + fortifyRptOutputDir)

    reload(sys)
    sys.setdefaultencoding('utf-8')
    fobj = open(fortifyRptOutputDir + '/report.html', 'w')

    total_count_base = 0
    iid_list_base = []
    Item_list_base = []
    if os.path.exists(fortifyXmlFileBaseDir):
        fortifyXmlFileBaseList = []
        basefilelist = os.listdir(fortifyXmlFileBaseDir)
        for basefile in basefilelist:
            if "fortify" in basefile:
                fortifyXmlFileBaseList.append(fortifyXmlFileBaseDir + "/" +
                                              basefile)
        if len(fortifyXmlFileBaseList) > 0:
            total_count_base, iid_list_base, Category_list_base, Friority_list_base, Abstract_list_base, FileName_list_base, LineStart_list_base, Item_list_base = count_critical_and_high(
                fortifyXmlFileBaseList)

    total_count_new = 0
    iid_list_new = []
    Item_list_new = []
    if os.path.exists(fortifyXmlFileNewDir):
        fortifyXmlFileNewList = []
        newfilelist = os.listdir(fortifyXmlFileNewDir)
        for newfile in newfilelist:
            if "fortify" in newfile:
                fortifyXmlFileNewList.append(fortifyXmlFileNewDir + "/" +
                                             newfile)
        if len(fortifyXmlFileNewList) > 0:
            total_count_new, iid_list_new, Category_list_new, Friority_list_new, Abstract_list_new, FileName_list_new, LineStart_list_new, Item_list_new = count_critical_and_high(
                fortifyXmlFileNewList)

    report = "<html>" + "\n" + "<head>" + "\n" + "<meta charset=\"UTF-8\"> </meta>" + "<title>" + "static_check_fortify" + "</title>" + "\n" + "</head>" + "\n" + "<body><center>" + "\n"
    report += "<h2>Fortify Report</h2>" + "\n"
    # report += "<p>Base Defects: " + str(total_count_base) + "&nbsp&nbsp&nbsp" + "Current Defects: " + str(total_count_new) + "</p>" + "\n"
    tr_str = "<tr bgcolor=\"#F8F8F2\">"
    tr_str += "<td>No.</td>"
    tr_str += "<td>Type</td>"
    tr_str += "<td>Priority</td>"
    tr_str += "<td>Description</td>"
    tr_str += "<td>File</td>"
    tr_str += "<td>Line</td>"
    tr_str += "</tr>" + "\n"

    No = 0

    for iid in iid_list_new:
        if not iid in iid_list_base:
            Index = iid_list_new.index(iid)
            Category = Category_list_new[Index]
            Friority = Friority_list_new[Index]
            Abstract = Abstract_list_new[Index]
            FileName = FileName_list_new[Index]
            LineStart = LineStart_list_new[Index]
            Item = Item_list_new[Index]
            if Item in Item_list_base:
                continue
            #gen report
            No = No + 1
            tr_str += "<tr bgcolor=\"#F8F8F2\">"
            tr_str += "<td>" + str(No) + "</td>"
            tr_str += "<td>" + str(Category) + "</td>"
            tr_str += "<td>" + str(Friority) + "</td>"
            tr_str += "<td>" + str(Abstract) + "</td>"
            tr_str += "<td>" + str(FileName) + "</td>"
            tr_str += "<td>" + str(LineStart) + "</td>"
            tr_str += "</tr>" + "\n"

    if No > 0:
        report += "<p>" + "<font color=\"blue\">New Defects : </font>" + "<font color=\"red\">" + str(
            No) + "</font></p>" + "\n"
        report += "<table cellPadding=\"8\">" + "\n"
        report += tr_str
        report += "</table>" + "\n"
        report += "</center></body>" + "\n" + "</html>"
        fobj.write(report)
        fobj.close()
    else:
        report += "<p><font color=\"blue\">" + "No New Defects" + "</font></p>" + "\n"
        report += "</center></body>" + "\n" + "</html>"
        fobj.write(report)
        fobj.close()

    return No
Example #32
0
import hashlib
import base64
import ConfigParser
import cookielib
import requests
import socket
timeout = 10
socket.setdefaulttimeout(timeout)

from bs4 import BeautifulSoup

# Ignore SSL error when accessing a HTTPS website
# ssl._create_default_https_context = ssl._create_unverified_context

reload(sys)
sys.setdefaultencoding( "gb2312" )

def logfile(log,logfile):
    f=open(logfile,'a')
    f.write(log+"\n")
    f.close

def isExisted(mystr,filepath):
    if os.path.exists(filepath):
        mystr=mystr.strip()
        f=open(filepath,'r')
        num=0
        for eachline in f:
            if mystr in eachline:
                num=num+1
            else:
Example #33
0
import httplib2
import urllib2
import os
from datetime import date
import calendar
import time
import tempfile
import sys
reload(sys)  
sys.setdefaultencoding('utf-8')

from apiclient import discovery
from oauth2client import client
from oauth2client import tools
from oauth2client.file import Storage
from apiclient.http import MediaFileUpload

try:
    import argparse
    flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
except ImportError:
    flags = None

SCOPES = 'https://www.googleapis.com/auth/drive.file' #create or upload file
CLIENT_SECRET_FILE = 'client_secret.json'
APPLICATION_NAME = 'Drive API Python Quickstart'

def get_credentials():
    """Gets valid user credentials from storage.

    If nothing has been stored, or if the stored credentials are invalid,
Example #34
0
from . import api, resource, case, checks, enum, request, rest
from .cache import cache

import sys
if sys.version_info.major == 2:
    reload(sys)
    sys.setdefaultencoding("UTF8")
Example #35
0
a = frozenset(range(10))     # 生成一个新的不可变集合
print a
b = frozenset('runoob')
print b

#long() 函数将数字或字符串转换为一个长整型。
print long()
print long(1)
print long('123')

#reload() 用于重新载入之前载入的模块

import sys
print sys.getdefaultencoding()            # 当前默认编码
print reload(sys)                         # 使用 reload
sys.setdefaultencoding('utf8')      # 设置编码
print sys.getdefaultencoding()

#vars() 函数返回对象object的属性和属性值的字典对象。
#返回对象object的属性和属性值的字典对象,如果没有参数,就打印当前调用位置的属性和属性值 类似 locals()。
print(vars())
class Runoob:
    a=1
print(vars(Runoob))
runoob = Runoob()
print(vars(runoob))

#classmethod 修饰符对应的函数不需要实例化,不需要 self 参数,但第一个参数需要是表示自身类的 cls 参数,可以来调用类的属性,类的方法,实例化对象等。

class A(object):
    bar = 1
Example #36
0
Created on 2014-3-3

@author: Administrator
'''

import os
import sys
import pysvn



try:
	default_encoding = 'utf-8'
	if sys.getdefaultencoding() != default_encoding:
		reload(sys)
		sys.setdefaultencoding(default_encoding)
	svn_home = os.path.join('..', '..', '..')
	_SettingDefinePath = os.path.join(svn_home, 'Tool', 'NetProtor', 'Setting', 'Setting.h')
	_ClientSettingOutPath = os.path.join(svn_home, 'Client', 'Assets', 'Code', 'Game', 'Modules', 'GameSetting', 'GameSettingDataExtend.cs')
	_ServerSettingOutPath = os.path.join(svn_home, 'server', 'gameserver', 'include', 'common', 'setting.hrl')
	from deps.setting.settingmaker import HrlWriter, CsWriter, PathFinder,MacroReader
except Exception,e:
	print e


def work():
	if os.path.isfile(_SettingDefinePath):
		reader = MacroReader(_SettingDefinePath)
		reader.run()
		if reader.hasReadError():
			print '\nReadError:'
def main():
    """
    TV for me
    """

    # do some preliminary stuff
    sickbeard.MY_FULLNAME = os.path.normpath(os.path.abspath(__file__))
    sickbeard.MY_NAME = os.path.basename(sickbeard.MY_FULLNAME)
    sickbeard.PROG_DIR = os.path.dirname(sickbeard.MY_FULLNAME)
    sickbeard.DATA_DIR = sickbeard.PROG_DIR
    sickbeard.MY_ARGS = sys.argv[1:]
    sickbeard.CREATEPID = False
    sickbeard.DAEMON = False

    sickbeard.SYS_ENCODING = None

    try:
        locale.setlocale(locale.LC_ALL, "")
        sickbeard.SYS_ENCODING = locale.getpreferredencoding()
    except (locale.Error, IOError):
        pass

    # For OSes that are poorly configured I'll just randomly force UTF-8
    if not sickbeard.SYS_ENCODING or sickbeard.SYS_ENCODING in ('ANSI_X3.4-1968', 'US-ASCII', 'ASCII'):
        sickbeard.SYS_ENCODING = 'UTF-8'

    if not hasattr(sys, "setdefaultencoding"):
        reload(sys)

    try:
        # pylint: disable=E1101
        # On non-unicode builds this will raise an AttributeError, if encoding type is not valid it throws a LookupError
        sys.setdefaultencoding(sickbeard.SYS_ENCODING)
    except:
        print 'Sorry, you MUST add the Sick Beard folder to the PYTHONPATH environment variable'
        print 'or find another way to force Python to use ' + sickbeard.SYS_ENCODING + ' for string encoding.'
        sys.exit(1)

    # Need console logging for SickBeard.py and SickBeard-console.exe
    consoleLogging = (not hasattr(sys, "frozen")) or (sickbeard.MY_NAME.lower().find('-console') > 0)

    # Rename the main thread
    threading.currentThread().name = "MAIN"

    try:
        opts, args = getopt.getopt(sys.argv[1:], "qfdp::", ['quiet', 'forceupdate', 'daemon', 'port=', 'pidfile=', 'nolaunch', 'config=', 'datadir='])  # @UnusedVariable
    except getopt.GetoptError:
        print "Available Options: --quiet, --forceupdate, --port, --daemon, --pidfile, --config, --datadir"
        sys.exit()

    forceUpdate = False
    forcedPort = None
    noLaunch = False

    for o, a in opts:
        # For now we'll just silence the logging
        if o in ('-q', '--quiet'):
            consoleLogging = False

        # Should we update (from tvdb) all shows in the DB right away?
        if o in ('-f', '--forceupdate'):
            forceUpdate = True

        # Suppress launching web browser
        # Needed for OSes without default browser assigned
        # Prevent duplicate browser window when restarting in the app
        if o in ('--nolaunch',):
            noLaunch = True

        # Override default/configured port
        if o in ('-p', '--port'):
            forcedPort = int(a)

        # Run as a daemon
        if o in ('-d', '--daemon'):
            if sys.platform == 'win32':
                print "Daemonize not supported under Windows, starting normally"
            else:
                consoleLogging = False
                sickbeard.DAEMON = True

        # Specify folder to load the config file from
        if o in ('--config',):
            sickbeard.CONFIG_FILE = os.path.abspath(a)

        # Specify folder to use as the data dir
        if o in ('--datadir',):
            sickbeard.DATA_DIR = os.path.abspath(a)

        # Write a pidfile if requested
        if o in ('--pidfile',):
            sickbeard.PIDFILE = str(a)

            # If the pidfile already exists, sickbeard may still be running, so exit
            if os.path.exists(sickbeard.PIDFILE):
                sys.exit("PID file '" + sickbeard.PIDFILE + "' already exists. Exiting.")

            # The pidfile is only useful in daemon mode, make sure we can write the file properly
            if sickbeard.DAEMON:
                sickbeard.CREATEPID = True
                try:
                    file(sickbeard.PIDFILE, 'w').write("pid\n")
                except IOError, e:
                    raise SystemExit("Unable to write PID file: %s [%d]" % (e.strerror, e.errno))
            else:
                logger.log(u"Not running in daemon mode. PID file creation disabled.")
    def get_pdf(self):
        reload(sys)
        planilla_ajustes = self.env['planilla.ajustes'].get_parametros_ajustes(
        )
        sys.setdefaultencoding('iso-8859-1')
        width, height = A4  # 595 , 842
        wReal = width - 30
        hReal = height - 40
        try:
            direccion = self.env['main.parameter.hr'].search([])[0].dir_create_file
        except: 
            raise UserError('Falta configurar un directorio de descargas en el menu Configuracion/Parametros/Directorio de Descarga')
        doc = SimpleDocTemplate(direccion+"CTS.pdf", pagesize=A4)

        colorfondo = colors.lightblue
        elements = []
        # Definiendo los estilos de la cabecera.
        styles = getSampleStyleSheet()
        styles.add(ParagraphStyle(name='Justify', alignment=TA_JUSTIFY))
        styles.add(ParagraphStyle(name='Center', alignment=TA_CENTER))
        styles.add(ParagraphStyle(name='LeftBold',
                                  fontSize=10,
                                  fontName='Times-Bold',

                                  ))
        styles.add(ParagraphStyle(name='Left',
                                  fontSize=10,
                                  fontName='Times-Roman',
                                  ))
        styles.add(ParagraphStyle(name='Tab',
                                  fontSize=10,
                                  fontName='Times-Roman',
                                  leftIndent=20,

                                  ))
        styles.add(ParagraphStyle(name='RightBold',
                                  fontSize=10,
                                  fontName='Times-Bold',
                                  alignment=TA_RIGHT,
                                  ))

        styles.add(ParagraphStyle(name='Right',
                                  fontSize=10,
                                  alignment=TA_RIGHT,
                                  fontName='Times-Roman',
                                  ))
        estilo_c = [
            ('SPAN', (0, 0), (1, 0)),
            ('SPAN', (2, 0), (3, 0)),
            ('ALIGN', (2, 0), (3, 0), 'RIGHT'),
            ('VALIGN', (0, 0), (-1, -1), 'TOP'),
        ]
        # ------------------------------------------------------Insertando Data-----------------------------------------
        lines = self.env['planilla.cts.line'].search(
            [('planilla_cts_id', '=', self.env.context['active_id'])])
        for line in lines:
            employee = self.env['hr.employee'].search(
                [('id', '=', line.employee_id.id)])
            name = line.names + ' ' + line.last_name_father + ' ' + line.last_name_mother
            # --------------------------------------------------Cabecera
            # a = Image(direccion+"calquipalleft.png")
            # a.drawHeight = 50
            # a.drawWidth = 95
            # b = Image(direccion+"calquipalright.png")
            # b.drawHeight = 60
            # b.drawWidth = 80
            cabecera = [['', '', '', ''], ]
            table_c = Table(cabecera, colWidths=[
                            120]*2, rowHeights=50, style=estilo_c)
            elements.append(table_c)
            elements.append(Spacer(0, 8))
            # ----------------------------------------------------Datos
            cadt = [[u'LIQUIDACIÓN DE DEPÓSITO SEMESTRAL DE CTS']]
            t = Table(cadt, colWidths=[450], rowHeights=[20])
            t.setStyle(TableStyle(
                [
                    ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
                    ('VALIGN', (0, -1), (-1, -1), 'TOP'),
                    ('FONTSIZE', (0, 0), (-1, -1), 14),
                    ('FONT', (0, 0), (-1, -1), 'Helvetica-Bold'),
                ]
            ))
            elements.append(t)
            elements.append(Spacer(0, 20))
            rc = self.env['res.company'].search([])[0]
            employee_name = employee.a_paterno+' '+employee.a_materno + \
                ' '+employee.nombres if employee.nombres else ''
            text = u"""<b>"""+(rc.name if rc.name else '')+u"""</b> con RUC <b>Nº """+(planilla_ajustes.ruc if planilla_ajustes.ruc else '')+"""</b>, domiciliada en """+(rc.street if rc.street else '')+""",
                                representado por su <b>"""+(self.encargado.job_id.name if self.encargado.job_id.name else '')+(u' Señor ' if self.encargado.gender == 'male' else u' Señora ')+self.encargado.name_related+u"""</b>,
                                en aplicación del artículo 24º del TUO del D.Leg Nº 650, Ley de Compensación por Tiempo de
                                Servicios, aprobado mediante el D.S. Nº 001-97-TR,
                                otorga a <b>"""+employee_name+u"""</b>,
                                la presente constancia del depósito de su compensación por Tiempo de Servicios realizado el %d de %s del %d""" % (fields.Date.from_string(self.fecha_deposito).day,self.env['planilla.helpers'].date_to_month(fields.Date.from_string(self.fecha_deposito).month), fields.Date.from_string(self.fecha_deposito).year)+u""" en la cuenta CTS """ + (u'(Dólares Americanos)' if employee.bacts_currency_id_rel.name == 'USD' else '(Soles)') + u"""
                    <b>Nº """+(line.cta_cts if line.cta_cts else '')+"""</b> del <b>"""+(line.banco.name if line.banco.name else '')+u"""</b>, por los siguientes montos y periodos:"""
            elements.append(Paragraph(text, styles["Justify"]))
            periodo = ''
            if line.planilla_cts_id.tipo == '07':
                periodo = 'Del 01 de Mayo del ' + line.planilla_cts_id.year + \
                    ' al 31 de Octubre del ' + line.planilla_cts_id.year
            else:
                periodo = 'Del 01 de Noviembre del ' + \
                    str(int(line.planilla_cts_id.year)-1) + \
                    ' al 30 de Abril del ' + line.planilla_cts_id.year
            periodo = periodo + ': ' + \
                str(line.meses) + ' meses, ' + str(line.dias) + u' días'
            datat = [
                [Paragraph('<b>1. <u>FECHA DE INGRESO</u>: </b>'+datetime.strptime(str(
                    line.fecha_ingreso), '%Y-%m-%d').strftime("%d/%m/%Y"), styles["Left"]), '', ''],
                [Paragraph('2. <u>PERIODO QUE SE LIQUIDA</u>:',
                           styles["LeftBold"]), '', ''],
                [Paragraph(periodo, styles["Tab"]), '', ''],
                [Paragraph('3. <u>REMUNERACION COMPUTABLE</u>:',
                           styles["LeftBold"]), '', ''],
                [Paragraph('-  Básico', styles["Tab"]), 'S/.', Paragraph(
                    '{:,.2f}'.format(decimal.Decimal("%0.2f" % line.basico)), styles["Right"])],
                [Paragraph('-  Asignación Familiar', styles["Tab"]), 'S/.', Paragraph(
                    '{:,.2f}'.format(decimal.Decimal("%0.2f" % line.a_familiar)), styles["Right"])],
                [Paragraph('-  Horas Extra', styles["Tab"]), 'S/.', Paragraph('{:,.2f}'.format(
                    decimal.Decimal("%0.2f" % line.horas_extras_mean)), styles["Right"])],
                [Paragraph('-  Gratificaciones', styles["Tab"]), 'S/.', Paragraph(
                    '{:,.2f}'.format(decimal.Decimal("%0.2f" % line.gratificacion)), styles["Right"])],
                [Paragraph('-  Bonificación', styles["Tab"]), 'S/.', Paragraph(
                    '{:,.2f}'.format(decimal.Decimal("%0.2f" % line.bonificacion)), styles["Right"])],
                [Paragraph('-  Comisión', styles["Tab"]), 'S/.', Paragraph(
                    '{:,.2f}'.format(decimal.Decimal("%0.2f" % line.comision)), styles["Right"])],
                [Paragraph('-  Feriados Trabajados', styles["Tab"]), 'S/.', Paragraph(
                    '{:,.2f}'.format(decimal.Decimal("%0.2f" % 0.00)), styles["Right"])],
                # [Paragraph('-  Inasistencias',styles["Tab"]),'S/.',Paragraph('{:,.2f}'.format(decimal.Decimal("%0.2f" % line.absences_total)),styles["Right"])],
            ]

            # conceptos = []
            n_lines = 0
            # for con in line.conceptos_lines:
            #     conceptos.append([Paragraph('-  '+con.concepto_id.name,styles["Tab"]),'S/.',Paragraph('{:,.2f}'.format(decimal.Decimal("%0.2f" % con.monto)),styles["Right"])])
            #     n_lines += 1
            # datat += conceptos

            datat += [[Paragraph('TOTAL', styles["RightBold"]), 'S/.', Paragraph('{:,.2f}'.format(decimal.Decimal("%0.2f" % line.base)), styles["RightBold"])],
                      ['', '', ''],
                      [Paragraph('<u>CALCULO</u>', styles["LeftBold"]), '', ''],
                      [Paragraph('  -  Por los meses completos:',
                                 styles["LeftBold"]), '', ''],
                      [Paragraph("S/. {0} ÷ 12 x {1} mes(es)".format(str(line.base), str(line.meses)), styles["Tab"]), 'S/.',
                       Paragraph('{:,.2f}'.format(decimal.Decimal("%0.2f" % line.monto_x_meses)), styles["Right"])],
                      [Paragraph('  -  Por los dias completos:',
                                 styles["LeftBold"]), '', ''],
                      [Paragraph("S/. {0} ÷ 12 ÷ 30 x {1} día(s)".format(str(line.base), str(line.dias)), styles["Tab"]),
                       'S/.', Paragraph('{:,.2f}'.format(decimal.Decimal("%0.2f" % line.monto_x_dias)), styles["Right"])],
                      [Paragraph('  -  Faltas:', styles["LeftBold"]), '', ''],
                      [Paragraph("S/. {0} ÷ 12 ÷ 30 x {1} día(s)".format(str(line.base), str(line.faltas)), styles["Tab"]),
                       'S/. ', Paragraph('{:,.2f}'.format(decimal.Decimal("%0.2f" % -line.total_faltas)), styles["Right"])],
                      [Paragraph('TOTAL', styles["RightBold"]), 'S/.', Paragraph('{:,.2f}'.format(
                          decimal.Decimal("%0.2f" % line.cts_soles)), styles["RightBold"])],
                      ['', '', ''], ]

            table2 = Table(datat, colWidths=[350, 20, 80])
            table2.setStyle(TableStyle(
                [
                    # ('BOX',(0,0),(-1,-1),2, colors.black),
                    # ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
                    ('FONTSIZE', (0, 0), (-1, -1), 10),
                    ('FONT', (0, 0), (-1, -1), 'Times-Bold'),
                    ('ALIGN', (0, 2), (-1, 2), 'RIGHT'),
                    ('LINEABOVE', (2, 11+n_lines),
                     (2, 11+n_lines), 1.3, colors.black),
                    ('LINEABOVE', (2, 20+n_lines),
                     (2, 20+n_lines), 1.3, colors.black),
                ]
            ))
            elements.append(Spacer(0, 1))
            elements.append(table2)
            if employee.bacts_currency_id_rel.name == 'USD':
                datat = [
                    [Paragraph('MONTO DEPOSITADO (*)', styles["LeftBold"]), '$', Paragraph(
                        '{:,.2f}'.format(decimal.Decimal("%0.2f" % line.cts_dolares)), styles["RightBold"])],
                    ['', '', ''],
                    [Paragraph("(*) Moneda Extranjera: Tipo de Cambio {0}".format(
                        str(line.tipo_cambio_venta)), styles["LeftBold"]), '', ''],
                    ['', '', ''],
                ]
                table3 = Table(datat, colWidths=[350, 20, 80])
                table3.setStyle(TableStyle(
                    [
                        # ('BOX',(0,0),(-1,-1),2, colors.black),
                        ('FONTSIZE', (0, 0), (-1, -1), 10),
                        ('FONT', (0, 0), (-1, -1), 'Times-Bold'),
                        ('BOX', (2, 0), (2, 0), 1.3, colors.black),
                    ]
                ))
                elements.append(table3)
            elements.append(Spacer(0, 50))
            dataf = [
                [(rc.name if rc.name else ''), '', employee_name],
                ['EMPLEADOR', '', "DNI: " +
                    employee.identification_id if employee.identification_id else ''],
                ['', '', 'TRABAJADOR(A)'],
            ]
            table4 = Table(dataf, colWidths=[200, 50, 200])
            table4.setStyle(TableStyle(
                [
                    ('FONTSIZE', (0, 0), (-1, -1), 10),
                    ('FONT', (0, 0), (-1, -1), 'Times-Bold'),
                    ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
                    ('LINEABOVE', (0, 0), (0, 0), 1.1, colors.black),
                    ('LINEABOVE', (2, 0), (2, 0), 1.1, colors.black),
                ]
            ))
            elements.append(table4)
            elements.append(PageBreak())
        doc.build(elements)

        f = open(direccion+'CTS.pdf', 'rb')

        vals = {
            'output_name': 'CTS.pdf',
            'output_file': f.read().encode("base64"),
        }

        sfs_id = self.env['planilla.export.file'].create(vals)

        return {
            "type": "ir.actions.act_window",
            "res_model": "planilla.export.file",
            "views": [[False, "form"]],
            "res_id": sfs_id.id,
            "target": "new",
        }
Example #39
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time     : 2016/12/17 19:14
# @Author   : Wang Hongqing
# @File     : mvc.py
# @Software : PyCharm

import os
import sys
import logging
import argparse
import datetime

reload(sys)
sys.setdefaultencoding("utf-8")

quotes = ('a', 'b', 'c', 'd')

class QuoteModel:
    def get_quote(self, n):
        try:
            value = quotes[n]
        except IndexError as err:
            value = 'Not Found'
        return value

class QuoteTerminalView:
    @staticmethod
    def show(self, quote):
        logger.info("the quote is %s" % (quote))
Example #40
0
# encoding=utf-8
import sys
import MySQLdb
from plus import ReadKeyWord

reload(sys)
sys.setdefaultencoding('utf-8')  # @UndefinedVariable
conn = MySQLdb.connect(host='localhost',
                       user='******',
                       passwd='toor',
                       db='work',
                       port=3306,
                       charset='utf8')
cursor = conn.cursor()
keyworks = ReadKeyWord()
count = 0
for (l, c) in enumerate(keyworks):
    if (l % 3 == 0):
        count = count + 1
    group = str(count)
    cursor.execute("INSERT INTO t_keyword(id,keyword,dTaskID) VALUES(" +
                   str(l) + ",'" + c + "'," + group + ")")
conn.commit()
cursor.close()
conn.close()
print "end"
Train 4 multiclass perceptron models with different parameters online
Training data is feedback on tweets corrct categories.
After trained about 80 tweets, models predict same 20 tweets and print the predictions.
Comparing the predictions with true labels

by Yilan Ji

"""

from pyspark import SparkContext
import numpy as np
from pyspark.sql import SparkSession, Row
import json
import sys
reload(sys)
sys.setdefaultencoding('UTF8')
from perceptron import PerceptronforRDD
from tweets_category_predict_perceptron import predictTweetCategPerceptron
from perceptronMulticlass import MulticlassPerceptron
sc = SparkContext()
spark = SparkSession.builder \
        .master("local") \
        .appName("Perceptron train News Category") \
        .config("spark.some.config.option", "some-value") \
        .getOrCreate()
raw_data = sc.textFile("data/tweetsCorrectIndex.txt")

lines = raw_data.map(lambda line: line.split("    ")).map(
    lambda line: (line[0], " ".join(line[1:])))
sentenceData = spark.createDataFrame(lines, ["label", "sentence"])
Example #42
0
# 常用方法
# Created by C.L.Wang

from __future__ import absolute_import

import collections
import os
import random
import shutil
import sys
import time
from datetime import timedelta, datetime

reload(sys)  # 重置系统参数
sys.setdefaultencoding('utf8')  # 避免编码错误

from dateutil.relativedelta import relativedelta

p = os.path.dirname(
    os.path.dirname(os.path.dirname(os.path.dirname(
        os.path.abspath(__file__)))))
if p not in sys.path:
    sys.path.append(p)

import glob
import json
import os
import re
import numpy as np
import operator
#################################################################################

#Graficall support
import wx
#Directory acces support
import os.path, dircache
#Regular expressions support
import re
#Scrolling pannel support
import wx.lib.scrolledpanel

#support for reading .gcno files
#Choosing workspace via workspace_choosing_button won't work otherwise
import sys
reload(sys)
sys.setdefaultencoding("ISO-8859-1")


#Popup window for displaying help
class HelpPopup(wx.PopupWindow):
    def __init__(self, parent, style):
        #Calling the constructor of the parent class
        super(HelpPopup, self).__init__(parent, style)
        #defining a panel on popup window
        self.help_panel = wx.Panel(self)
        #definig a static text display on panel for showing help content
        self.help_text = wx.StaticText(
            self.help_panel,
            -1, "Workflow:\n\n"
            "1. Choose workspace:\n"
            "    - press button: \"Choose workspace\"\n"
Example #44
0
#!/usr/bin/env python
#coding:utf-8

import json
from urllib import urlopen
import sys
reload(sys)                      #要reload一次sys才能使用setdefaultencoding函数

sys.setdefaultencoding('utf-8')  #要将系统默认字符编码设置为utf-8,在Goldendict才能正常输出

html = """
<html>
<head>
<script type="text/javascript">function playSound(){var ky = document.getElementById("key");var word = ky.childNodes[0].nodeValue;var api = "http://dict.youdao.com/dictvoice?audio=" + encodeURIComponent(word);var ado = document.getElementById("media");try{ado.ended = true;ado.setAttribute("src",api);ado.load();ado.play();return false;}catch(err){alert(err.description);return false;}}</script>
</head>
<body>
<style type="text/css">
      div.block {
      border:1px solid #BEBEBE;
      background:#F0F0F0;
      margin-left:20px;
      border-radius: 5px;
      }
      div.name {
      margin-top:10px;
      margin-bottom:5px;
      margin-left:20px;
      font-size:13px;
      font-weight:bold;
      }
      div.item {
Example #45
0
#coding=utf8
"""
from tansuozhe:djq002
"""
import urllib2
import HTMLParser
from BeautifulSoup import BeautifulSoup
from lxml import html
import MySQLdb
import re
import sys
import requests
import socket
socket.setdefaulttimeout(10.0)
reload(sys)
sys.setdefaultencoding("utf-8")  # 重新加载系统并设置默认编码


#------------------------------------------------------------------------------
#---------------------------- 定义操作mysql函数 step1-------------------------
#------------------------------------------------------------------------------
def mysqlexe(sql):
    db = MySQLdb.connect('localhost',
                         'root',
                         'djq002',
                         'python',
                         charset='utf8')
    cur = db.cursor()
    cur.execute(sql)
    result = cur.fetchall()
    db.commit()
Example #46
0
    def start(self):
        # do some preliminary stuff
        sickbeard.MY_FULLNAME = os.path.normpath(os.path.abspath(__file__))
        sickbeard.MY_NAME = os.path.basename(sickbeard.MY_FULLNAME)
        sickbeard.PROG_DIR = os.path.dirname(sickbeard.MY_FULLNAME)
        sickbeard.DATA_DIR = sickbeard.PROG_DIR
        sickbeard.MY_ARGS = sys.argv[1:]
        sickbeard.SYS_ENCODING = None

        try:
            locale.setlocale(locale.LC_ALL, "")
            sickbeard.SYS_ENCODING = locale.getpreferredencoding()
        except (locale.Error, IOError):
            pass

        # For OSes that are poorly configured I'll just randomly force UTF-8
        if not sickbeard.SYS_ENCODING or sickbeard.SYS_ENCODING in ('ANSI_X3.4-1968', 'US-ASCII', 'ASCII'):
            sickbeard.SYS_ENCODING = 'UTF-8'

        if not hasattr(sys, "setdefaultencoding"):
            reload(sys)
  
        if sys.platform == 'win32':
            if sys.getwindowsversion()[0] >= 6 and sys.stdout.encoding == 'cp65001':
                sickbeard.SYS_ENCODING = 'UTF-8'

        try:
            # pylint: disable=E1101
            # On non-unicode builds this will raise an AttributeError, if encoding type is not valid it throws a LookupError
            sys.setdefaultencoding(sickbeard.SYS_ENCODING)
        except:
            sys.exit("Sorry, you MUST add the SickRage folder to the PYTHONPATH environment variable\n" +
                     "or find another way to force Python to use " + sickbeard.SYS_ENCODING + " for string encoding.")

        # Need console logging for SickBeard.py and SickBeard-console.exe
        self.consoleLogging = (not hasattr(sys, "frozen")) or (sickbeard.MY_NAME.lower().find('-console') > 0)

        # Rename the main thread
        threading.currentThread().name = "MAIN"

        try:
            opts, args = getopt.getopt(sys.argv[1:], "hfqdp::",
                                       ['help', 'forceupdate', 'quiet', 'nolaunch', 'daemon', 'pidfile=', 'port=',
                                        'datadir=', 'config=', 'noresize'])  # @UnusedVariable
        except getopt.GetoptError:
            sys.exit(self.help_message())

        for o, a in opts:
            # Prints help message
            if o in ('-h', '--help'):
                sys.exit(self.help_message())

            # For now we'll just silence the logging
            if o in ('-q', '--quiet'):
                self.consoleLogging = False

            # Should we update (from indexer) all shows in the DB right away?
            if o in ('-f', '--forceupdate'):
                self.forceUpdate = True

            # Suppress launching web browser
            # Needed for OSes without default browser assigned
            # Prevent duplicate browser window when restarting in the app
            if o in ('--nolaunch',):
                self.noLaunch = True

            # Override default/configured port
            if o in ('-p', '--port'):
                try:
                    self.forcedPort = int(a)
                except ValueError:
                    sys.exit("Port: " + str(a) + " is not a number. Exiting.")

            # Run as a double forked daemon
            if o in ('-d', '--daemon'):
                self.runAsDaemon = True
                # When running as daemon disable consoleLogging and don't start browser
                self.consoleLogging = False
                self.noLaunch = True

                if sys.platform == 'win32' or sys.platform == 'darwin':
                    self.runAsDaemon = False

            # Write a pidfile if requested
            if o in ('--pidfile',):
                self.CREATEPID = True
                self.PIDFILE = str(a)

                # If the pidfile already exists, sickbeard may still be running, so exit
                if os.path.exists(self.PIDFILE):
                    sys.exit("PID file: " + self.PIDFILE + " already exists. Exiting.")

            # Specify folder to load the config file from
            if o in ('--config',):
                sickbeard.CONFIG_FILE = os.path.abspath(a)

            # Specify folder to use as the data dir
            if o in ('--datadir',):
                sickbeard.DATA_DIR = os.path.abspath(a)

            # Prevent resizing of the banner/posters even if PIL is installed
            if o in ('--noresize',):
                sickbeard.NO_RESIZE = True

        # The pidfile is only useful in daemon mode, make sure we can write the file properly
        if self.CREATEPID:
            if self.runAsDaemon:
                pid_dir = os.path.dirname(self.PIDFILE)
                if not os.access(pid_dir, os.F_OK):
                    sys.exit("PID dir: " + pid_dir + " doesn't exist. Exiting.")
                if not os.access(pid_dir, os.W_OK):
                    sys.exit("PID dir: " + pid_dir + " must be writable (write permissions). Exiting.")

            else:
                if self.consoleLogging:
                    sys.stdout.write("Not running in daemon mode. PID file creation disabled.\n")

                self.CREATEPID = False

        # If they don't specify a config file then put it in the data dir
        if not sickbeard.CONFIG_FILE:
            sickbeard.CONFIG_FILE = os.path.join(sickbeard.DATA_DIR, "config.ini")

        # Make sure that we can create the data dir
        if not os.access(sickbeard.DATA_DIR, os.F_OK):
            try:
                os.makedirs(sickbeard.DATA_DIR, 0744)
            except os.error, e:
                raise SystemExit("Unable to create datadir '" + sickbeard.DATA_DIR + "'")
Example #47
0
#!/usr/bin/env python
# coding=utf-8

# Created by zhaohongwei on 2018-10-23
# Blog: http://blog.csdn.net/z_johnny

import sys
reload(sys)
sys.setdefaultencoding('gbk')