def send(self): config.log(u'Sender email %s' % (self.mp['title'] if self.mp['title'] else self)) if config.options.catchup: config.log(u'(sendes faktisk ikke pga --catch-up)') return self.store() msg = self.asEmail() # Open smtp connection if config.options.smtphostname: if config.options.smtpport == 465: server = smtplib.SMTP_SSL(config.options.smtphostname, config.options.smtpport) else: server = smtplib.SMTP(config.options.smtphostname, config.options.smtpport) else: server = smtplib.SMTP('localhost') # server.set_debuglevel(1) if config.options.smtpusername: try: server.starttls() except smtplib.SMTPException: pass # ok, but we tried... server.login(config.options.smtpusername, config.options.smtppassword) server.sendmail(config.options.senderemail, config.options.email, msg.as_string()) server.quit() # Ensure that we only send once self.store()
def getmotd(sock, addr, data): '''A client getmotd request: log the client information and then send the response''' addrstr = '<< {0}'.format(addr) try: _, infostr = data.split('\\', 1) except ValueError: infostr = '' info = Info(infostr) rinfo = Info() try: log_client(addr, info) except KeyError as err: log(LOG_PRINT, addrstr, 'Client not logged: missing info key', err, sep = ': ') except ValueError as err: log(LOG_PRINT, addrstr, 'Client not logged', err, sep = ': ') else: log(LOG_VERBOSE, addrstr, 'Recorded client stat', sep = ': ') try: rinfo['challenge'] = info['challenge'] except KeyError: log(LOG_VERBOSE, addrstr, 'Challenge missing or invalid', sep = ': ') rinfo['motd'] = config.getmotd() if not rinfo['motd']: return response = '\xff\xff\xff\xffmotd {0}'.format(rinfo) log(LOG_DEBUG, '>> {0}: {1!r}'.format(addr, response)) safe_send(sock, response, addr)
def skoleLogin(): global br, resp 'Login to the SkoleIntra website' global _skole_login_done if _skole_login_done: return br = getBrowser() config.log(u'Login', 2) URL_LOGIN = u'https://%s/Infoweb/Fi2/Login.asp' % config.HOSTNAME config.log(u'Login på skoleintra') err = True try: config.log(u'skoleLogin: URL %s' % URL_LOGIN, 2) br.open(URL_LOGIN) err = False except Exception, e: if 'EOF occurred in violation of protocol' in str(e.reason): config.log(u'skoleLogin: Prøver igen med sslfix') import sslfix config.log(u'skoleLogin: URL %s' % URL_LOGIN, 2) try: br.open(URL_LOGIN) err = False except Exception, e: pass
def deserialise(): count = 0 with open('serverlist.txt') as f: for line in f: if not line: continue try: addr = Addr(line) except sockerr as err: log(LOG_ERROR, 'Could not parse address in serverlist.txt', repr(line), err.strerror, sep = ': ') except ValueError as err: log(LOG_ERROR, 'Could not parse address in serverlist.txt', repr(line), str(err), sep = ': ') else: addrstr = '<< {0}:'.format(addr) log(LOG_DEBUG, addrstr, 'Read from the cache') if addr.family not in outSocks.keys(): famstr = {AF_INET: 'IPv4', AF_INET6: 'IPv6'}[addr.family] log(LOG_PRINT, addrstr, famstr, 'not available, dropping from cache') else: # fake a heartbeat to verify the server as soon as # possible could cause an initial flood of traffic, but # unlikely to be anything that it can't handle heartbeat(addr, '') count += 1 log(LOG_VERBOSE, 'Read', count, 'servers from cache')
def updatePersonDate(self, phtml=None): if phtml: d = phtml.renderContents().decode('utf-8') else: d = self.mp['data'] assert(type(d) == unicode) # must be unicode # e.g. front page pics m = re.findall(u'>(?:Lagt ind|Skrevet) af ([^<]*?) den ([-0-9]*?)<', d) if m: m = m[-1] self.setSender(m[0]) self.setDate(m[1]) return m = re.findall(u'(?s)<small>Besked fra([^<]*?) - (?:modtaget|sendt) ' u'den ([^<]*?)</small>', d) if not m: m = re.findall(u'(?s)<small>Oprettet af([^<]*?) ' u'den ([^<]*?)</small>', d) if m: m = m[0] self.setSender(m[0].strip()) self.setDate(m[1].strip()) return else: # neither Sender nor date/time found config.log('No sender found', 2) return
def send_challenge(self): '''Sends a getinfo challenge and records the current time''' self.challenge = challenge() packet = '\xff\xff\xff\xffgetinfo ' + self.challenge log(LOG_DEBUG, '>> {0}: {1!r}'.format(self, packet)) safe_send(self.sock, packet, self.addr) self.set_timeout(time() + config.CHALLENGE_TIMEOUT)
def safe_send(sock, data, addr): '''Network failures happen sometimes. When they do, it's best to just keep going and whine about it loudly than die on the exception.''' try: sock.sendto(data, addr) except sockerr as err: log(LOG_ERROR, 'ERROR: sending to', addr, 'failed with error:', err.strerror)
def closeKinectStream(): if config.depth_stream is not None: config.depth_stream.stop() openni2.unload() config.openKinectFailureLogged = False config.dev = None config.kinectReady = False config.log(f"kinect depth stream stopped and openni unloaded")
def exposed_getDepth(self, orientation, tableHeight=920): config.log( f"getDepth request received, orientation: {orientation}, tableHeight: {tableHeight}" ) obstacles = kinect.obstacleMap(orientation, tableHeight) config.log(f"return obstacles, None: {obstacles is None}") return obstacles
def redo(self): for each in self.records: log(0x16, 'Processor.redo:', each['name']) func = self.__getattribute__(each['name']) if func: func(**each['args'], record=False) else: raise NameError("Unknown Function %s" % each['name'])
async def on_command(ctx): now = datetime.now().strftime('%H:%M') command = ctx.message.content.split(" ")[0] if command != "!lep": arguments = ctx.message.content.replace(command, "") config.log( f"{ctx.message.author.name}: {ctx.message.author.id} executed the {command} command with arguments: {arguments}" )
def __init__(self, properties): super().__init__(properties) try: self.handle = cv2.VideoCapture(self.deviceId, cv2.CAP_DSHOW) except Exception as e: config.log(f"could not connect with cam {self.name}") self.handle = None
def _unjoin(self): with self._lock: if self._is_finished: return # Need to unjoin even if there's only 1 entity (as it may already be joined # to something else, we do not know). scc.log(self._app, self, 'Unjoining: %s' % self._entity_id) self._app.call_service(SONOS_SERVICE_UNJOIN, entity_id=self._entity_id)
def rotateCartAbsolute(degrees): """ stub for rotate cart, speed is ROTATION_SPEED :param degrees: :return: """ config.log(f"rotate cart absolut to {degrees}") moveCart()
def nextMove(self): if self.currMove == self.numMoves - 1: self.sequenceStatus = MoveSequenceState.MOVESEQUENCE_FINISHED return else: self.currMove += 1 config.log(f"continue with next move in sequence") self.startOrContinueMoveSequence()
def publish(context): # will not be bankrupt if we reach here agentId = context.tradeReceiver log("game", "Agent {} has been asked for a trade response!".format(agentId)) return [agentId]
def skoleDocuments(): global bs # surllib.skoleLogin() config.log(u"Kigger efter nye dokumenter") # read the initial page bs = surllib.skoleGetURL(URL_MAIN, True, True) docFindDocuments(bs)
def neededProcessesRunning(processes) -> bool: for process in processes: if not process in config.marvinShares.processDict.keys(): config.log( f"task {config.task} requires process {process} but it is not running, request ignored" ) navManager.setTask("needed processes not running", "notask") return False return True
def _worker(params): key, args = params config.log(f' ... {key}') if key == 'capnp': return capnp.generate(*args) elif key == 'class_hierarchy': return class_hierarchy.generate(*args) elif key == 'classes': return classes.generate(*args) elif key == 'clone_tree_cpp': return clone_tree_cpp.generate(*args) elif key == 'containers_h': return containers_h.generate(*args) elif key == 'Copier': for source, destination in args[0].items(): file_utils.copy_file_if_changed(source, destination) return True elif key == 'ElaboratorListener_cpp': return ElaboratorListener_cpp.generate(*args) elif key == 'serializer': return serializer.generate(*args) elif key == 'uhdm_forward_decl_h': return uhdm_forward_decl_h.generate(*args) elif key == 'uhdm_h': return uhdm_h.generate(*args) elif key == 'uhdm_types_h': return uhdm_types_h.generate(*args) elif key == 'vpi_listener': return vpi_listener.generate(*args) elif key == 'vpi_user_cpp': return vpi_user_cpp.generate(*args) elif key == 'vpi_visitor_cpp': return vpi_visitor_cpp.generate(*args) elif key == 'VpiListener_h': return VpiListener_h.generate(*args) elif key == 'VpiListenerTracer_h': return VpiListenerTracer_h.generate(*args) config.log('ERROR: Unknown key "{key}"') return False
def get_data_files(): data_path = "data/training_data/labeled_games" files = glob(f"{data_path}/*.csv") config.log(f"Game files: {len(files)}") seed = 2042 np.random.seed(seed) np.random.shuffle(files) return files
def updateBatteryStatus(): config._batteryStatus = psutil.sensors_battery() setLastBatteryCheckTime(time.time()) # inform navManager about low battery if config._batteryStatus.percent < 25 and not config._batteryStatus.power_plugged: msg = f"low battery: {config._batteryStatus.percent:.0f} percent" config.log(msg)
def skoleWeekplans(): global bs surllib.skoleLogin() config.log(u'Kigger efter nye ugeplaner') # read the initial page bs = surllib.skoleGetURL(urlMain(), True, True) wpFindWeekplans(bs)
def set_data(self, *args): try: self.name = args[0] self.phone = args[1] self.city = args[2] self.who = args[3] self.doing = args[4] except Exception as e: config.log(Error=e, text="SET_DATA_ERROR_OCCURED")
def test_log_debugFalse(self): config.DEBUG = False # mock 'print' function capturedOutput = StringIO.StringIO() sys.stdout = capturedOutput test = "test" config.log(test) result = capturedOutput.getvalue().strip() self.assertEqual(result, "")
def servoFeedbackDefinitions(arduinoIndex, pin, servoFeedback): msg = f"8,{pin},{servoFeedback.i2cMultiplexerAddress},{servoFeedback.i2cMultiplexerChannel}," msg += f"{servoFeedback.feedbackMagnetOffset},{servoFeedback.feedbackInverted}," msg += f"{servoFeedback.degPerPos}," msg += f"{servoFeedback.kp},{servoFeedback.ki},{servoFeedback.kd},\n" sendArduinoCommand(arduinoIndex, msg) config.log(f"feedback definitions sent: {servoFeedback}")
def requestAllServosStop(): config.log(f"all servos stop requested") config.moveRequestBuffer.clearBuffer() config.moveRequestBuffer.clearServoActiveList() msg = f"3,\n" for i in range(config.numArduinos): if config.arduinoConn[i] is not None: sendArduinoCommand(i, msg) time.sleep(1) # allow some time to stop
def skoleWeekplans(): global bs # surllib.skoleLogin() config.log(u'Kigger efter nye ugeplaner') # read the initial page bs = surllib.skoleGetURL(URL_MAIN, True, True) wpFindWeekplans(bs)
def on_disconnect(self, conn): callerName = "unknown" try: callerName = conn._channel.stream.sock.getpeername() except Exception as e: config.log(f"on_disconnect, could not get peername: {e}") print( f"{config.serverName} - on_disconnect triggered, conn: {callerName}" )
def _join(self): with self._lock: if self._is_finished: return scc.log(self._app, self, 'Joining \'%s\' to: %s' % (self._entity_id, self._primary)) self._app.call_service(SONOS_SERVICE_JOIN, master=self._primary, entity_id=self._entity_id)
def on_Rest_pressed(self): servoStatic: mg.ServoStatic = config.md.servoStaticDict[self.selectedServoName] degrees = servoStatic.restDeg position = config.evalPosFromDeg(self.selectedServoName, degrees) config.log(f"requestRestPosition, servoName: {self.selectedServoName}, degrees: {degrees}, pos: {position}") #arduinoSend.requestServoPosition(self.selectedServoName, position, config.REST_MOVE_DURATION) config.sc.positionServo(config.md.servoRequestQueue, self.selectedServoName, position, config.REST_MOVE_DURATION) # set request position slider self.RequestPositionSlider.setValue(round(position))
def _action_speak(self, kwargs=None): with self._lock: if self._is_finished: return scc.log(self._app, self, 'Speaking on %s: \'%s\'' % (self._entity_id, self._message)) self._app.call_service(self._tts_service, entity_id=self._entity_id, message=self._message) self._schedule_action_complete()
def gamestat(addr, data): '''Delegates to log_gamestat, cutting the first token (that it asserts is 'gamestat') from the data''' assert data.startswith('gamestat') try: log_gamestat(addr, data[len('gamestat'):].lstrip()) except ValueError as err: log(LOG_PRINT, '<< {0}: Gamestat not logged'.format(addr), err) return log(LOG_VERBOSE, '<< {0}: Recorded gamestat'.format(addr))
def get(index): global loaded_tileset if not loaded_tileset: config.log('No tileset loaded.', 'ERROR') return None if not index > 0: return None if tilesets[loaded_tileset]['tiles'][index] is None: config.log(images[loaded_tileset]['tiles'][index] + ': No such image.', 'ERROR') return images[index]
def fn(self): # get value of the slider through the slider get value function name position = eval(sliderGetValueFunction) config.log(f"sliderReleased, servoName: {servoName}, position: {position}") # do not filter on sliderRelease request as it is the final position of the slider #arduinoSend.requestServoPosition(servoName, position, 500, filterSequence=False) config.md.servoRequestQueue.put()
def find1orFail(bs, sel, asText=False): 'Find a single tag matching sel or fail' hits = bs.select(sel) if len(hits) != 1: config.log(u"'%s' var %d gange på siden (!=1)" % (sel, len(hits)), -1) sys.exit(1) hit = hits[0] if asText: hit = hit.text.strip() return hit
def setVerbose(newState: bool): try: if newState: msg = b'v,1' + b',\n' else: msg = b'v,0' + b',\n' config.log(f"setVerbose, {msg=}") config.arduino.write(msg) except: pass
def get_weather(message): if message.text.lower()[:7] == 'погода ': s_city_name = message.text[7:] log(message) city_id = Weather.get_city_id(s_city_name) conditions, temp = Weather.request_current_weather(city_id) bot.send_message( message.chat.id, 'Состояние погоды в городе {2}: {0} \nТемпература = {1}'.format( conditions, temp, s_city_name))
def skoleSelectChild(name): global _children, URL_PREFIX assert(name in _children) if name == config.CHILDNAME: config.log(u'[%s] er allerede valgt som barn' % name) else: config.log(u'Vælger [%s]' % name) url = URL_PREFIX + _children[name] _ = surllib.skoleGetURL(url, False, noCache=True) config.CHILDNAME = name
def connect(self, IPname, family, hostaddr): ''' incoming connection example parameters: IPname='mx.example.com', family=AF_INET, hostaddr=('23.5.4.3',4720) ..., family=AF_INET6, hostaddr=('3ffe:80e8:d8::1', 4720, 1, 0) ''' self.gpgm_body = None config.log("connect from %s at %s" % (IPname, hostaddr)) return Milter.CONTINUE
def initialize(tileset): # This is where the images are converted from indexes to actual images. global loaded_tileset clear() if tileset not in tilesets: config.log('No such tileset: ' + tileset, 'ERROR') return for tile in tilesets[tileset]['tiles']: images[tile] = pygame.image.load(image_dir + tilesets[tileset]['tiles'][tile]) loaded_tileset = tileset tilesets[tileset]['initialized'] = True
def req(self,url,body=()): if len(body)==0: req=urllib2.Request(url) else: req=urllib2.Request(url,urllib.urlencode(body)) config.log('%s?%s' % (url, urllib.urlencode(body))) try: raw=urllib2.urlopen(req) except: config.log('access %s failed' % url) sys.exit(1) return raw.read()
def skoleGetURL(url, asSoup=False, noCache=False, perChild=True, postData=None): '''Returns data from url as raw string or as a beautiful soup''' if type(url) == unicode: url, uurl = url.encode('utf-8'), url else: uurl = url.decode('utf-8') # FIXME? fix urls without host names # Sometimes the URL is actually an empty string if not url: data = '' if asSoup: data = beautify(data) data.cachedate = datetime.date.today() return data else: return data if type(postData) == dict: postData = urllib.urlencode(postData) lfn = url2cacheFileName(url, perChild, postData) if os.path.isfile(lfn) and not noCache and not config.SKIP_CACHE: config.log('skoleGetURL: Henter fra cache %s' % uurl, 2) data = open(lfn, 'rb').read() else: qurl = urllib.quote(url, safe=':/?=&%') msg = u'Trying to fetch %s' % qurl if perChild: msg += u' child='+config.CHILDNAME if postData: msg += u' '+postData config.log(u'skoleGetURL: %s' % msg, 2) skoleLogin() br = getBrowser() resp = br.open(qurl, postData) data = resp.read() # write to cache ldn = os.path.dirname(lfn) if not os.path.isdir(ldn): os.makedirs(ldn) open(lfn, 'wb').write(data) if asSoup: data = beautify(data) data.cachedate = datetime.date.fromtimestamp(os.path.getmtime(lfn)) data.cacheage = (time.time() - os.path.getmtime(lfn))/(24 * 3600.) return data else: return data
def prune_timeouts(slist = servers[None]): '''Removes from the list any items whose timeout method returns true''' # iteritems gives RuntimeError: dictionary changed size during iteration for (addr, server) in slist.items(): if server.timed_out(): del slist[addr] remstr = str(count_servers()) if server.lastactive: log(LOG_VERBOSE, '{0} dropped due to {1}s inactivity ' '({2})'.format(server, time() - server.lastactive, remstr)) else: log(LOG_VERBOSE, '{0} dropped: no response ' '({1})'.format(server, remstr))
def heartbeat(addr, data): '''In response to an incoming heartbeat, find the associated server. If this is a flatline, delete it, otherwise send it a challenge, creating it if necessary and adding it to the list.''' label = find_featured(addr) addrstr = '<< {0}:'.format(addr) if 'dead' in data: if label is None: if addr in servers[None].keys(): log(LOG_VERBOSE, addrstr, 'flatline, dropped') del servers[label][addr] else: log(LOG_DEBUG, addrstr, 'flatline from unknown server, ignored') else: # FIXME: we kind of assume featured servers don't go down log(LOG_DEBUG, addrstr, 'flatline from featured server :(') elif config.max_servers >= 0 and count_servers() >= config.max_servers: log(LOG_PRINT, 'Warning: max server count exceeded, ' 'heartbeat from', addr, 'ignored') else: # fetch or create a server record label = find_featured(addr) s = servers[label][addr] if addr in servers[label].keys() else Server(addr) s.send_challenge() servers[label][addr] = s
def setDateTime(self, dt): assert(type(dt) == unicode) ts = time.localtime() # Use NOW by default dt2 = dt.split(',')[-1].strip().replace('.', '') if ':' not in dt2: dt2 += ' 12:00' try: # 25. jun. 2018 16:26 ts = time.strptime(dt2, '%d %b %Y %H:%M') except ValueError: config.log(u'Ukendt tidsstempel %r' % dt, -1) assert(False) # FIXME We should never be here self.mp['date_string'] = dt self.mp['date_ts'] = ts self.mp['date'] = time.strftime('%Y-%m-%d', ts) self.mp['date-set'] = True
def skoleGetURL(url, asSoup=False, noCache=False): '''Returns data from url as raw string or as a beautiful soup''' if type(url) == unicode: url, uurl = url.encode('utf-8'), url else: uurl = url.decode('utf-8') # FIXME? fix urls without host names # Sometimes the URL is actually an empty string if not url: data = '' if asSoup: data = beautify(data) data.cachedate = datetime.date.today() return data else: return data lfn = url2cacheFileName(url) if os.path.isfile(lfn) and not noCache and not config.SKIP_CACHE: config.log('skoleGetURL: Henter fra cache %s' % uurl, 2) data = open(lfn, 'rb').read() else: qurl = urllib.quote(url, safe=':/?=&%') config.log(u'skoleGetURL: Trying to fetch %s' % qurl, 2) skoleLogin() br = getBrowser() resp = br.open(qurl) data = resp.read() # write to cache ldn = os.path.dirname(lfn) if not os.path.isdir(ldn): os.makedirs(ldn) open(lfn, 'wb').write(data) if asSoup: data = beautify(data) data.cachedate = datetime.date.fromtimestamp(os.path.getmtime(lfn)) return data else: return data
def skoleLogin(): 'Login to the SkoleIntra website' global _skole_login_done if _skole_login_done: return br = getBrowser() config.log(u'Login', 2) URL_LOGIN = u'https://%s/Infoweb/Fi2/Login.asp' % config.HOSTNAME config.log(u'Login på skoleintra') br.open(URL_LOGIN) br.select_form(name='FrontPage_Form1') br.form.set_all_readonly(False) br['fBrugernavn'] = config.USERNAME br['MD5kode'] = config.PASS_MD5 br.submit() # we ignore the response and assume that things are ok _skole_login_done = True
def skoleDialogue(): surllib.skoleLogin() br = surllib.getBrowser() for tray in TRAYS: config.log(u'Behandler beskeder i bakken %s' % tray) url = 'https://%s%s%s' % (config.HOSTNAME, URL_BOX_PREFIX, tray) # Read the initial page, and search for messages config.log(u'Bakke-URL: %s' % url) resp = br.open(url) data = resp.read() # ensure that we get only mgss for the current child br.select_form(name='FrontPage_Form1') br['R1'] = ('klasse',) resp = br.submit() data = resp.read() diaFindMessages(data)
def send(self): config.log(u'Sender email %s' % (self.mp['title'] if self.mp['title'] else self)) msg = self.asEmail() # open smtp connection if config.SMTPHOST: server = smtplib.SMTP(config.SMTPHOST, config.SMTPPORT) else: server = smtplib.SMTP('localhost') # server.set_debuglevel(1) if config.SMTPLOGIN: try: server.starttls() except SMTPException: pass # ok, but we tried... server.login(config.SMTPLOGIN, config.SMTPPASS) server.sendmail(config.SENDER, config.EMAIL, msg.as_string()) server.quit() # ensure that we only send once self.store()
def getChildren(): '''Returns of list of "available" children in the system''' global _children def ckey(n): return tuple(n.rsplit(' ', 1)[::-1]) if not _children: _children = dict() seen = set() config.log(u'Henter liste af børn') data = surllib.skoleLogin() # Name of "First child" fst = data.find(id="sk-personal-menu-button").text.strip() for a in data.findAll('a', href=re.compile('^(/[^/]*){3}/Index$')): url = a['href'].rsplit('/', 1)[0].rstrip('/') if url in seen: continue seen.add(url) name = a.text.strip() or fst if name not in _children: config.log(u'Barn %s => %s' % (name, url), 2) _children[name] = url cns = sorted(_children.keys(), key=ckey) config.log(u'Følgende børn blev fundet: ' + u', '.join(cns)) return sorted(_children.keys(), key=ckey)
def checkSeat(self): #130527200212051639 body=(("queryMonths","2014-04"),("queryProvinces",11),("_",int(time.time()*1000))) url="http://ielts.etest.net.cn/myHome/1968462/queryTestSeats?%s" % urllib.urlencode(body) req = urllib2.Request(url) req.add_header('Accept','text/html,application/xhtml+xml,application/xml,application/json') req.add_header('X-Requested-With','XMLHttpRequest') try: raw = urllib2.urlopen(req) except: config.log('access %s failed' % url) sys.exit(1) res = raw.read() if self.debug: open('%s/seats.res' % config.dir_data(),'a').write(res) obj = json.loads(res) seats=[] seatNum=0 if not type(obj) is dict: open('%s/bad.res' % config.dir_data(), 'a').write(res) config.log('check seats failed') return seats for day in obj.keys(): for center in obj[day]: seatNum+=1 if center['levelCode']=='A/G' and center['optStatus']==1: seats.append(center['seatGuid']) config.log('%d seats found from %d seats' % (len(seats), seatNum)) if not 0==len(seats): self.sms('trying') return seats
def diaExamineMessage(url, mid): '''Look at the url and mid. Returns True iff an email was sent''' bs = surllib.skoleGetURL(url, True) # first, find main text tr = bs.find('tr', valign='top') assert(tr) phtml = tr.find('td') msg = semail.Message(u'dialogue', phtml) msg.setMessageID(mid) # next, look at the header header = bs.find('table', 'linje1') assert(header) # there must be a header headerLines = header.findAll('tr') assert(len(headerLines) >= 3) # there must be something inside the header for hl in headerLines: txt = hl.text if not txt: continue # ignore elif txt.startswith(u'Denne besked slettes'): pass # ignore elif hl.find('h4'): # title msg.setTitle(txt) elif txt.startswith(u'Besked fra') or txt.startswith(u'Oprettet af'): # Besked fra Frk Nielsen - modtaget den 26-09-2012 20:29:44 msg.updatePersonDate(hl) elif txt.startswith(u'Sendt til '): # Sendt til ... msg.setRecipient(txt.split(u' ', 2)[-1]) elif txt.startswith(u'Kopi til '): # Sendt til ... msg.setCC(txt.split(u' ', 2)[-1]) else: config.log(u'Ukendt header i besked #%s: %s' % (mid, txt), -1) return msg.maybeSend()
def store(self): mid = self.getMessageID() dn = os.path.join(config.options.msgdir, self.getLongMessageID()) if os.path.isdir(dn): # Already stored - ignore! return False tdn = dn + '.tmp' if os.path.isdir(tdn): config.log(u'Fjerner tidligere midlertidigt bibliotek %r' % tdn, 2) shutil.rmtree(tdn) # Remove stuff os.mkdir(tdn) fd = open(os.path.join(tdn, mid + '.eml'), 'wb') fd.write(str(self.asEmail())) fd.close() fd = open(os.path.join(tdn, mid + '.json'), 'wb') json.dump(self.mp, fd, sort_keys=True, indent=2, default=unicode) fd.close() os.rename(tdn, dn) return True
def store(self): mid = self.getMessageID() dn = os.path.join(config.MSG_DN, self.getLongMessageID()) if os.path.isdir(dn): # already stored - ignore! return False tdn = dn + '.tmp' if os.path.isdir(tdn): config.log('Removing previous temporary directory %s' % repr(tdn), 2) shutil.rmtree(tdn) # Remove stuff os.mkdir(tdn) fd = open(os.path.join(tdn, mid + '.eml'), 'wb') fd.write(str(self.asEmail())) fd.close() mpp = [(unicode(k), unicode(v)) for (k, v) in self.mp.items()] fd = codecs.open(os.path.join(tdn, mid + '.txt'), 'wb', 'utf-8') fd.write(repr(mpp)) fd.close() os.rename(tdn, dn) return True
def skoleGetChildren(): '''Returns of list of "available" children in the system''' global URL, _children # ensure that we are logged in # surllib.skoleLogin() # done automatically later config.log(u'Henter liste af børn') if not _children: data = surllib.skoleGetURL(URL, asSoup=True, noCache=True) _children = {} for a in data.findAll('a'): href = a['href'] name = a.span.text if name == SKOLEBESTYRELSE_NAME: config.log(u'Ignorerer [%s]' % name) continue _children[name] = href return sorted(_children.keys())