darknet-lantern/scripts/tests/csvwork.py

104 lines
3.6 KiB
Python

import csv, json, pandas as pd, glob
def main():
#print("aaa")
csvfile="verified.csv"
df = pd.read_csv(csvfile)
##############################################################################
print('\n[+] list the entire csv file and get all row IDs')
print(df[['Name', 'URL']])
index=-1
while (index > df.tail(1).index.item() or index < 0):
#index=input("\n[+] What entry do you want to edit ? (enter the row index (ex: 4)")
index=4
index=int(index)
print(df.iloc[index], "last index:", df.index.stop-1)
print("\n[+] Number of Rows:", len(df.index)-1)
print('\n[+] Iterate over the rows by their IDs for the 2 Columns URL and Name')
print(df.iterrows())
for i,j in df.iterrows():
#print("[+] ROW=",i,"\n[+] CONTENT=\n",j)
#print("[+] ROW=",i)
#print("[+] ROW CONTENTS= \n",df.loc[i, ['URL','Name']])
#print("[+] ROW CONTENTS= \n",df.loc[i, ['URL']])
print("[+] ROW=",i,"ROW CONTENTS=", df.at[i, 'Name'], df.at[i, 'URL'])
#print(df[0][i])
print('\n[+] Iterate over the columns by their name:')
columns = list(df)
print(columns)
print('\n[+] Iterate over the columns of the first row:')
for i in columns:
print('\nCOLUMN=',i)
print('CONTENTS=',df[i][0])
#print('[+] list the csv file by filtering a keyword and get all row IDs')
#filterterm=input("[+] Filter the CSV file using a keyword (ex: DNM)")
filterterm="Psy"
filter_df = df[df.Name.str.contains(filterterm)]
#print(filtered_df) # print all columns
print(filter_df[['Name','URL']]) #print only 2 columns
#print("\n[+] Number of Rows:", len(filter_df.index))
#for index in filter_df.index:
#print(index)
index=-1
while (index not in filter_df.index):
#index=int(input("\n[+] Please select a valid row: "))
index=int("12")
print("ROW=",index, 'CONTENT=', filter_df.at[index, 'Name'], filter_df.at[index, 'URL'])
print("\n[+] Adding a new row:")
# ask for the following:
#unverifiedpath=instancepath+'/unverified.csv'
instance='uptime.nowherejezfoltodf4jiyl6r56jnzintap5vyjlia7fkirfsnfizflqd.onion'
unverifiedpath='verified.csv'
# the name of the website (required) + check if its valid
# if the website name is "exit" then get out of the while loop
#entry_name = input("What is the Website name ?")
name="NewWebsite"
category="TestCategory"
# the url of the website (required) + check if its valid
#entry_url = input("What is URL of the Website ? (ex: https://torproject.org or http://2gzyxa5ihm7nsggfxnu52rck2vv4rvmdlkiu3zzui5du4xyclen53wid.onion)")
url="http://newwebsitewoidwajiawdhjoidwahjoadiwhj.onion"
# a quick description (optional) + check if its valid
#entry_desc = input("(Optional) Description of the website ? (max 256 characters) (press enter to skip)")
desc="This is a new website that we add, it has this description"
# sensitive ? (y/n) + check if its valid
#entry_sensi = input("is it a sensitive website ? (ex: website related to drugs) (y/n)")
sensi = "n"
newrow=[instance,category,name,url,sensi,desc,'','']
print("[+] NEWROW=",newrow)
#add a new row (get all the new data you need first):
df.loc[-1] = newrow # adding a row
df.index = df.index + 1 # shifting index
df = df.sort_index() # sorting by index
print("[+] New row added! now writing the csv file:")
df.to_csv(csvfile, index=False)
print(df)
print()
###########
# list every word in the blacklist wordlist csv file
# for each word, check if it matches with any of the rows in unverified.csv
# if it matches (on any column!), remove that row and write to the csv file
# list every word in the sensitive wordlist csv file
# if it matches (on any column!), mark the sensitive column as V
if __name__ == '__main__':
main()