#!usr/local/bin/python3.3
'''Loading python3 also loads 3.3 if it is available, so just load 3.3 (or 3.3.3)'''

'''Getting the module'''
import os
import sys
import re
import subprocess
from os import listdir
from os.path import isfile, join

check = 0
fileLst = []
dictLink = {}

while(check != 1):
    directory = input("Enter the full path of the directory: ")
    if os.path.exists(directory) == True:    #check if directory exists
        recur = input("Would you like to recursively look through the path? (y) (n): ")
        if recur == "y":
            check = 1
            for dirName, subdirlist, fileName in os.walk(directory): #Walking through the directory and store full path
                for name in fileName:
                    lst= dirName + "/" + name
                    fileLst.append(lst)
        elif recur == "n":
            check = 1
            for fileName in listdir(directory): #Find all the file at current directory
                tmpPath = join(directory,fileName)  #add the filename to the full path
                if isfile(tmpPath):
                    fileLst.append(tmpPath)
        else:
            print("Not a valid option")
    else:
        print("Not a valid path")

if len(fileLst) == 0:   #Empty list terminate the program
        sys.exit("Current path have no files")

# Extract distinct (unique) download history locations via the terminal
downloadHistory = os.popen("sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'select distinct LSQuarantineDataURLString from LSQuarantineEvent'").read()

for fname in fileLst:       
    #Use mdls and grep for the url
    proc1 = subprocess.Popen(["mdls", fname], stdout =subprocess.PIPE)
    proc2 = subprocess.Popen(["grep", "http"], stdin=proc1.stdout, stdout=subprocess.PIPE)
    url = str(proc2.communicate()[0])

    if url == "b\'\'": #if there is no url
        dictLink[fname] = "Can't determine the source of the website"
    else:
        link = url.split("\"")[1]
        histList = downloadHistory.split("\n")
        for dlink in histList:
                if link == dlink:
                        print("The file " + fname + " was found on this system with the download link " + link + " and was downloaded on this system.\n")

@@ -240,18 +240,8 @@
 in%0A%0A
-check = 0%0A
 file
@@ -267,260 +267,361 @@
  %7B%7D%0A
-%0Awhile(check !
+lenArgv = len(sys.argv)%0A%0Aif lenArgv =
 = 1
-)
 :%0A    
-directory = input(%22Enter the full path of the directory: %22)%0A    if os.path.exists(directory) == True:    #check if directory exists%0A        recur = input(%22Would you like to recursively look through the path? (y) (n): 
+sys.exit(%22TraceLink.py Synopsis:%5Cnpython3.3 tracelink.py %5Bdir%5D%5Cnpython3.3 tracelink.py %5Bopition%5D %5Bdir%5D%5Cn%5CnCommand line option:%5Cn-r, recursion is enable.%5Cn%22)%0A%0Aelif 2 %3C= lenArgv %3C= 3:%0A    if sys.argv%5B1%5D == '-r':%0A        if lenArgv %3C 3:%0A            sys.exit(%22Full path of directory was not provide.
 %22)%0A
+%0A
         
 if r
@@ -620,46 +620,93 @@
     
+el
 if 
-recur == %22y%22:%0A            check = 1
+os.path.isdir(sys.argv%5B2%5D):%0A            directory = os.path.abspath(sys.argv%5B2%5D)
 %0A   
@@ -946,20 +946,17 @@
 nd(lst)%0A
-    
+%0A
     elif
@@ -960,48 +960,85 @@
 lif 
-recur == %22n%22:%0A            check = 1%0A    
+os.path.isdir(sys.argv%5B1%5D):%0A        directory = os.path.abspath(sys.argv%5B1%5D)%0A
     
@@ -1129,20 +1129,16 @@
         
-  
-  
 tmpPath 
@@ -1212,20 +1212,16 @@
         
-    
 if isfil
@@ -1240,36 +1240,32 @@
                 
-   
- 
 fileLst.append(t
@@ -1272,20 +1272,16 @@
 mpPath)%0A
-    
     else
@@ -1294,81 +1294,36 @@
     
-    print(%22Not a valid option%22)%0A    else:%0A        print(%22Not a valid path
+sys.exit(%22Invalid formatting
 %22)%0A%0A

The program run like a cli