Exemple #1
0
def usage():
    """Print usage info."""
    usage_str = (
        "GFYP Core - Find domain variants and send alerts\n"
        "usage: python core.py [$BOLD$-escapealert$END$]\n"
        "Options:\n"
        "    $BOLD$-escapealert$END$ - Escape periods in email alert to avoid "
        "spam filter")
    pretty_print(usage_str)
    sys.exit()
	def get(self):

		pretty_state = False
		if config.Mode == 'DEBUG':
			logger.debug('Request URI: %s' % self.request.uri)
			if self.request.arguments.has_key('pretty'):
				pretty_state = self.get_argument('pretty')

		if config.Mode == 'DEBUG' and pretty_state is not None and pretty_state:
			self.set_header('Content-Type', 'text/html; charset=UTF-8')
		else:
			self.set_header('Content-Type', 'application/json; charset=UTF-8')

		if datetime.datetime.now() < MusicTopHandler.music_top_cache_expire_time + interval:
			res_ = MusicTopHandler.music_top_cache
			if config.Mode == 'DEBUG' and pretty_state is not None and pretty_state:
				res_ = common.pretty_print(res_)
			self.write(res_)
			return
		content_from_api = None
		try:
			response = urllib2.urlopen(BAIDU_TOP_URI)
			content_from_api = response.read()
			response.close()
		except Exception, e:
			logger.error('HTTP request error (from music.baidu.com/top/new/week), %s' % e)
			self.write(-1)
			return
Exemple #3
0
def usage():
    """Print usage info."""
    usage_str = (
        "GFYP Utilities\n"
        "usage: python util.py <$BOLD$command$END$> [command parameters space "
        "separated]\n"
        "Commands:\n"
        "    $BOLD$usage$END$ - prints this message\n"
        "    $BOLD$build$END$ - creates a blank database named db.db\n"
        "    $BOLD$add$END$ (domain name) (email address) - inserts a new "
        "domain to monitor into db.db\n"
        "    $BOLD$removemonitor$END$ (domain name) - removes a domain from "
        "being monitored\n"
        "    $BOLD$removeentry$END$ (domain name) - removes an identified "
        "domain from the found entries\n"
        "    $BOLD$dump$END$ (file name) - Writes the contents of the found "
        "domain name table into the file in CSV format")
    pretty_print(usage_str)
    sys.exit()
Exemple #4
0
def usage():
    """Print usage info."""
    usage_str = (
        "GFYP Utilities\n"
        "usage: python util.py <$BOLD$command$END$> [command parameters space "
        "separated]\n"
        "Commands:\n"
        "    $BOLD$usage$END$ - prints this message\n"
        "    $BOLD$build$END$ - creates a blank database named db.db\n"
        "    $BOLD$add$END$ (domain name) (email address) [optional: filename of csv file containing additional tlds] - inserts a new "
        "domain(s) to monitor into db.db\n"
        "    $BOLD$removemonitor$END$ (domain name) - removes a domain from "
        "being monitored\n"
        "    $BOLD$removeentry$END$ (domain name) - removes an identified "
        "domain from the found entries\n"
        "    $BOLD$dump$END$ (file name) - Writes the contents of the found "
        "domain name table into the file in CSV format\n"
        "    $BOLD$migrate$END$ - Upgrades the GFYP database to the most "
        "recent schema format\n"
        "    $BOLD$addnote$END$ (domain name) (note in quotes)- Add a note "
        "to a discovered domain entry")
    pretty_print(usage_str)
    sys.exit()
	def get(self):

		pretty_state = False
		if config.Mode == 'DEBUG':
			logger.debug('Request URI: %s' % self.request.uri)
			if self.request.arguments.has_key('pretty'):
				pretty_state = self.get_argument('pretty')

		if config.Mode == 'DEBUG' and pretty_state is not None and pretty_state:
			self.set_header('Content-Type', 'text/html; charset=UTF-8')
		else:
			self.set_header('Content-Type', 'application/json; charset=UTF-8')

		city_name = None
		if self.request.arguments.has_key('city'):
			city_name = self.get_argument('city')
		if city_name is None or len(city_name) == 0:
			logger.error('Missing argument \'city\'')
			self.write(201)
			return
		raw_city_name = city_name
		city_name = self.name_parse(city_name)
		if city_name is None or len(city_name) == 0:
			logger.error('No matching area name (%s)' % raw_city_name)
			self.write(201)
			return
		res_box = None
		WeatherHandler.lock_city_name_result_map.acquire()
		try:
			res_box = WeatherHandler.city_name_result_map.get(city_name)
		finally:
			WeatherHandler.lock_city_name_result_map.release()
		if res_box is not None:
			res_ = res_box.get('res')
			time_ = res_box.get('time')
			if res_ is not None and time_ is not None and datetime.datetime.now() < time_ + interval:
				res_ = res_ % raw_city_name
				if config.Mode == 'DEBUG' and pretty_state is not None and pretty_state:
					res_ = common.pretty_print(res_)
				self.write(res_)
				return
		content_from_api = None
		try:
			response = urllib2.urlopen(WEATHER_API_URI % city_name)
			content_from_api = response.read()
			response.close()
		except Exception, e:
			logger.error('HTTP request error (from thinkpage.cn), %s' % e)
			self.write(501)
			return
Exemple #6
0
	def get(self):

		pretty_state = False
		if config.Mode == 'DEBUG':
			logger.debug('Request URI: %s' % self.request.uri)
			if self.request.arguments.has_key('pretty'):
				pretty_state = self.get_argument('pretty')

		if config.Mode == 'DEBUG' and pretty_state is not None and pretty_state:
			self.set_header('Content-Type', 'text/html; charset=UTF-8')
		else:
			self.set_header('Content-Type', 'application/json; charset=UTF-8')

		keyword = None
		if self.request.arguments.has_key('keyword'):
			keyword = self.get_argument('keyword')
		if keyword is None or len(keyword) == 0:
			logger.error('Missing argument \'keyword\'')
			self.write(-2)
			return
		res_box = None
		NewsHandler.lock_news_keyword_result_map.acquire()
		try:
			res_box = NewsHandler.news_keyword_result_map.get(keyword)
		finally:
			NewsHandler.lock_news_keyword_result_map.release()
		if res_box is not None:
			res_ = res_box.get('res')
			time_ = res_box.get('time')
			if res_ is not None and time_ is not None and datetime.datetime.now() < time_ + interval:
				if config.Mode == 'DEBUG' and pretty_state is not None and pretty_state:
					res_ = common.pretty_print(res_)
				self.write(res_)
				return
		content_from_api = None
		try:
			response = urllib2.urlopen(BAIDU_NEWS_URI % keyword)
			content_from_api = response.read()
			response.close()
		except Exception, e:
			logger.error('HTTP request error (from news.baidu.com), %s' % e)
			self.write(-1)
			return
	def get(self):

		pretty_state = False
		if config.Mode == 'DEBUG':
			logger.debug('Request URI: %s' % self.request.uri)
			if self.request.arguments.has_key('pretty'):
				pretty_state = self.get_argument('pretty')

		if config.Mode == 'DEBUG' and pretty_state is not None and pretty_state:
			self.set_header('Content-Type', 'text/html; charset=UTF-8')
		else:
			self.set_header('Content-Type', 'application/json; charset=UTF-8')

		song_name = None
		if self.request.arguments.has_key('song'):
			song_name = self.get_argument('song')
		if song_name is None or len(song_name) == 0:
			logger.error('Missing argument \'song\'')
			self.write(-2)
			return
		res_box = None
		LrcSearchHandler.lock_song_name_result_map.acquire()
		try:
			res_box = LrcSearchHandler.song_name_result_map.get(song_name)
		finally:
			LrcSearchHandler.lock_song_name_result_map.release()
		if res_box is not None:
			res_ = res_box.get('res')
			time_ = res_box.get('time')
			if res_ is not None and time_ is not None and datetime.datetime.now() < time_ + interval:
				if config.Mode == 'DEBUG' and pretty_state is not None and pretty_state:
					res_ = common.pretty_print(res_)
				self.write(res_)
				return
		content_from_api = None
		try:
			response = urllib2.urlopen(BAIDU_LRC_URI % song_name)
			content_from_api = response.read()
			response.close()
		except Exception, e:
			logger.error('HTTP request error (from music.baidu.com/search/lrc), %s' % e)
			self.write(-1)
			return
Exemple #8
0
    rotated_files = sorted(files_list, reverse=True)
    # print(f'After sorting: {rotated_files}')
    return [os.path.join(file_path, listed_files[0])] + rotated_files
"""
# pseudocode:
# get all the files in applog dir
listed_files = os.listdir(file_path)
# form full path for the files
# skip webapp.log and 
files_list = [os.path.join(file_path, file) for file in listed_files[1:]]
# reverse sort all other files
sorted(files_list, reverse=True)
# append webapp.log and reversed file names
[os.path.join(file_path, listed_files[0])] + rotated_files
"""

if __name__ == '__main__':
    # from log_parser.models import Config
    #
    # d = read_json_config(APP_CONFIG)
    # pretty_print(d)
    # for i in d:
    #     pretty_print(i)
    #     config = Config(**i)

    files = get_files(r'C:\Users\schandramohan\Documents\swadhi\test_git\log_parser\logs\web_app')
    pretty_print(files)

    # logs = get_log_files_for_app('web_app_2')
    # pretty_print(logs)
Exemple #9
0
					text_ = link_.get_text()
					if text_ is None:
						text_ = ''
					title_ = ('{ ' +
						'"url": "%s", ' % href_ +
						'"title": "%s"' % text_ +
						' }')
					titles_.append(title_)
			if titles_ is not None and len(titles_) > 0:
				titles_str = ','.join(titles_)
				res += titles_str
		res += ']'
		res += ' }'
		NewsHandler.lock_news_keyword_result_map.acquire()
		try:
			NewsHandler.news_keyword_result_map[keyword] = {
				'res': res,
				'time': datetime.datetime.now()
			}
		finally:
			NewsHandler.lock_news_keyword_result_map.release()
		if config.Mode == 'DEBUG' and pretty_state is not None and pretty_state:
			res = common.pretty_print(res)
		self.write(res)


	def write(self, trunk):
		if type(trunk) == int:
			trunk = str(trunk)
		super(NewsHandler, self).write(trunk)