<s> import sys <EOL> import os <EOL> from Maltego import * <EOL> import stawk_db <EOL> import logging <EOL> import datetime <EOL> from common import * <EOL> logging . basicConfig ( level = logging . DEBUG , filename = '<STR_LIT>' , format = '<STR_LIT>' , datefmt = '<STR_LIT>' ) <EOL> sys . stderr = sys . stdout <EOL> def main ( ) : <EOL> print "<STR_LIT>" ; <EOL> MaltegoXML_in = sys . stdin . read ( ) <EOL> if MaltegoXML_in < > '<STR_LIT>' : <EOL> m = MaltegoMsg ( MaltegoXML_in ) <EOL> cursor = stawk_db . dbconnect ( ) <EOL> TRX = MaltegoTransform ( ) <EOL> drone = '<STR_LIT:%>' <EOL> now = datetime . datetime . now ( ) <EOL> if '<STR_LIT>' in m . AdditionalFields and '<STR_LIT>' in m . AdditionalFields : <EOL> start_time = m . AdditionalFields [ '<STR_LIT>' ] <EOL> end_time = m . AdditionalFields [ '<STR_LIT>' ] <EOL> else : <EOL> start_time = now + datetime . timedelta ( seconds = - lookback ) <EOL> end_time = now + datetime . timedelta ( seconds = lookback ) <EOL> now = now . strftime ( "<STR_LIT>" ) <EOL> start_time = start_time . strftime ( "<STR_LIT>" ) <EOL> end_time = end_time . strftime ( "<STR_LIT>" ) <EOL> if '<STR_LIT:location>' in m . AdditionalFields : <EOL> location = m . AdditionalFields [ '<STR_LIT:location>' ] <EOL> else : <EOL> location = "<STR_LIT:%>" <EOL> if '<STR_LIT>' in m . AdditionalFields : <EOL> drone = m . AdditionalFields [ '<STR_LIT>' ] <EOL> cursor . execute ( "<STR_LIT>" ) <EOL> results = cursor . fetchall ( ) <EOL> for row in results : <EOL> country = "<STR_LIT>" <EOL> num = - <NUM_LIT:1> <EOL> try : <EOL> country = row [ <NUM_LIT:0> ] . encode ( '<STR_LIT:utf8>' , '<STR_LIT>' ) <EOL> num = row [ <NUM_LIT:1> ] <EOL> except Exception , e : <EOL> logging . debug ( e ) <EOL> NewEnt = TRX . addEntity ( "<STR_LIT>" , country ) ; <EOL> NewEnt . addAdditionalFields ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:strict>" , num ) <EOL> NewEnt . addAdditionalFields ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:strict>" , country ) <EOL> NewEnt . setWeight ( num ) <EOL> TRX . returnOutput ( ) <EOL> try : <EOL> main ( ) <EOL> except Exception , e : <EOL> logging . debug ( e ) </s>
