Python Forum
do you have an idea to optimize this code[recursion]]?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
do you have an idea to optimize this code[recursion]]?
#1
Bug 
thanks
netanel

class l():
    def __init__(self,name,created_on,last_valid_on):
        self.name=name
        self.created_on=created_on
        self.last_valid_on=last_valid_on
class y():
    def __init__(self, id, indicator,type,deleted=False,published_date=0,last_updated=0,reports=[],actors=[],
    malware_families=[''],kill_chains=[''],ip_address_types=[],domain_types=[],malicious_confidence='',labels=[l('',time.time(),time.time())],relations=[t('','','',time.time(),time.time(),indic='')]):
        self.id=id
        self.indicator=indicator
        self.type=type
        self.deleted=deleted
        self.published_date=datetime.datetime.fromtimestamp(published_date).strftime("%b %d %Y %H:%M:%S")
        self.last_updated=datetime.datetime.fromtimestamp(last_updated).strftime("%b %d %Y %H:%M:%S")
        self.reports=reports
        self.actors=actors
        self.relations=recursive_indicator(indicator,1)
    def recursive_indicator(i,rec=2):
#    li.append(f"{i} is found")
    #ax=pd.DataFrame(data=i["relations"])
        if rec>-1:
            if(i["relations"]==None):
                return ""
        else:
            

            return (y(recursive_indicator(i,rec=rec-1)))               

 
class t():
    def __init__(self,id, indicator,type,created_date,last_valid_date,indic):
        self.id=id
        self.indicator=indicator
        self.type=type
        self.indic=y.recursive_indicator(indicator)
        self.created_date=datetime.datetime.fromtimestamp(created_date).strftime("%b %d %Y %H:%M:%S")
        self.last_valid_date=datetime.datetime.fromtimestamp(last_valid_date).strftime("%b %d %Y %H:%M:%S")

              
       
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020