Python errors. List in post -
i have couple of python errors dont understand how can fix them.
thanks.
list of errors:
traceback (most recent call last): file "c:\users\----\desktop\wm3con-master\wm3con-master\wm3con.py", line 277, in <module> sys.exit(main()) file "c:\users\----\desktop\wm3con-master\wm3con-master\wm3con.py", line 274, in main return curses.wrapper(app.run_curses_app) file "c:\python32\lib\curses\wrapper.py", line 43, in wrapper return func(stdscr, *args, **kwds) file "c:\users\----\desktop\wm3con-master\wm3con-master\wm3con.py", line 230, in run_curses_app m.set_data(self.data) file "c:\users\----\desktop\wm3con-master\wm3con-master\wm3con.py", line 114, in set_data dets = data.get('detections', []) attributeerror: 'nonetype' object has no attribute 'get'
edit: .py file's code below (converted 2 3) thing not work , dont know guys mean data none.
this f-secures world map ascii edition. converted version 2 3.
.py file's code below:
#!/usr/bin/env python ''' f-secure virus world map console edition see readme.md more details copyright 2012-2013 jyrki muukkonen released under mit license. see license.txt or http://www.opensource.org/licenses/mit-license.php ascii map in map-world-01.txt copyright: "map 1998 matthew thomas. freely usable long line included" ''' import curses import json import locale import os import random import sys import time import urllib.request, urllib.error, urllib.parse streams = { 'filetest': 'wm3stream.json', 'wm3': 'http://worldmap3.f-secure.com/api/stream/', } maps = { 'world': { # offset (as (y, x) curses...) 'corners': (1, 4, 23, 73), # lat top, lon left, lat bottom, lon right 'coords': [90.0, -180.0, -90.0, 180.0], 'file': 'map-world-01.txt', } } class asciimap(object): """ helper class handling map drawing , coordinate calculations """ def __init__(self, map_name='world', map_conf=none, window=none, encoding=none): if map_conf none: map_conf = maps[map_name] open(map_conf['file'], 'rb') mapf: self.map = mapf.read() self.coords = map_conf['coords'] self.corners = map_conf['corners'] if window none: window = curses.newwin(0, 0) self.window = window self.data = [] self.data_timestamp = none # json contents _should_ utf8 (so, python internal unicode here...) if encoding none: encoding = locale.getpreferredencoding() self.encoding = encoding # check if can use transparent background or not if curses.can_change_color(): curses.use_default_colors() background = -1 else: background = curses.color_black tmp_colors = [ ('red', curses.color_red, background), ('blue', curses.color_blue, background), ('pink', curses.color_magenta, background) ] self.colors = {} if curses.has_colors(): i, (name, fgcolor, bgcolor) in enumerate(tmp_colors, 1): curses.init_pair(i, fgcolor, bgcolor) self.colors[name] = def latlon_to_coords(self, lat, lon): """ convert lat/lon coordinates character positions. naive version, assumes drawing whole world todo: filter out stuff doesn't fit todo: make possible use "zoomed" maps """ width = (self.corners[3]-self.corners[1]) height = (self.corners[2]-self.corners[0]) # change 0-180, 0-360 abs_lat = -lat+90 abs_lon = lon+180 x = (abs_lon/360.0)*width + self.corners[1] y = (abs_lat/180.0)*height + self.corners[0] return int(x), int(y) def set_data(self, data): """ set / convert internal data. selects random set show (good enough demo purposes) todo: use deque show entries """ entries = [] formats = [ "{name} / {country} {city}", "{name} / {country}", "{name}", "{type}", ] dets = data.get('detections', []) det in random.sample(dets, min(len(dets), 5)): #"city": "montoire-sur-le-loir", #"country": "fr", #"lat": "47.7500", #"long": "0.8667", #"name": "trojan.generic.7555308", #"type": "trojan" desc = "detection" # keeping unicode here, encode() curses later on fmt in formats: try: desc = fmt.format(**det) break except exception: pass entry = ( float(det['lat']), float(det['long']), '*', desc, curses.a_bold, 'red', ) entries.append(entry) self.data = entries # debugging... maybe shown again have live stream support #self.data_timestamp = data.get('response_generated') def draw(self, target): """ draw internal data curses window """ self.window.clear() self.window.addstr(0, 0, self.map) debugdata = [ (60.16, 24.94, '*', self.data_timestamp, curses.a_bold, 'blue'), # helsinki #(90, -180, '1', 'top left', curses.a_bold, 'blue'), #(-90, -180, '2', 'bottom left', curses.a_bold, 'blue'), #(90, 180, '3', 'top right', curses.a_bold, 'blue'), #(-90, 180, '4', 'bottom right', curses.a_bold, 'blue'), ] # fixme: position defined in map config? row = self.corners[2]-6 items_to_show = 5 lat, lon, char, desc, attrs, color in debugdata + self.data: # make work everywhere. see http://docs.python.org/2/library/curses.html if desc: desc = desc.encode(self.encoding, 'ignore') if items_to_show <= 0: break char_x, char_y = self.latlon_to_coords(lat, lon) if self.colors , color: attrs |= curses.color_pair(self.colors[color]) self.window.addstr(char_y, char_x, char, attrs) if desc: det_show = "%s %s" % (char, desc) else: det_show = none if det_show not none: try: self.window.addstr(row, 1, det_show, attrs) row += 1 items_to_show -= 1 except exception: # fixme: check window size before addstr() break self.window.overwrite(target) self.window.leaveok(1) class mapapp(object): """ virus world map ncurses application """ def __init__(self, conf=none): conf = dict(conf or []) # stream url can known name, filename or url stream_url = conf.get('stream_url', 'wm3') stream_url = streams.get(stream_url, stream_url) if '://' not in stream_url , os.path.isfile(stream_url): stream_url = 'file://' + os.path.abspath(stream_url) self.stream_url = stream_url #self.replay = true self.data = none self.last_fetch = 0 self.sleep = 10 # tenths of seconds, curses.halfdelay() def fetch_data(self, epoch_now, force_refresh=false): """ (re)fetch data json stream """ refresh = false if force_refresh or self.data none: refresh = true else: # json data has: "polling_interval": 120 try: poll_interval = int(self.data['polling_interval']) except (valueerror, keyerror): poll_interval = 60 if self.last_fetch + poll_interval <= epoch_now: refresh = true if refresh: try: self.data = json.load(urllib.request.urlopen(self.stream_url)) self.last_fetch = epoch_now except exception: pass return refresh def run_curses_app(self, scr): """ initialize , run application """ m = asciimap() curses.halfdelay(self.sleep) while true: = int(time.time()) refresh = self.fetch_data(now) m.set_data(self.data) m.draw(scr) scr.addstr(0, 1, "f-secure virus world map '99", curses.a_bold) scr.addstr(0, 40, time.strftime("%c utc", time.gmtime(now)).rjust(37), curses.a_bold) event = scr.getch() if event == ord("q"): break # if in replay mode? #elif event == ord('-'): # self.sleep = min(self.sleep+10, 100) # curses.halfdelay(self.sleep) #elif event == ord('+'): # self.sleep = max(self.sleep-10, 10) # curses.halfdelay(self.sleep) elif event == ord('r'): # force refresh refresh = true elif event == ord('c'): # enter config mode pass elif event == ord('h'): # show screen pass elif event == ord('m'): # cycle maps pass # redraw window (to fix encoding/rendering bugs , hide other messages same tty) # user pressed 'r' or new data fetched if refresh: m.window.redrawwin() def main(argv=none): """ main function / entry point """ if argv none: argv = sys.argv[1:] conf = {} if len(argv): conf['stream_url'] = argv[0] app = mapapp(conf) return curses.wrapper(app.run_curses_app) if __name__ == '__main__': sys.exit(main())
data
none
. should check how got , why none
.
Comments
Post a Comment