Skip to content

Commit 2884b54

Browse files
Delete Files code
1 parent a7ae7e1 commit 2884b54

4 files changed

Lines changed: 286 additions & 0 deletions

File tree

Regex/token.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import re
2+
3+
token = '851568417:AAH3cOtvVaJ9RATU3cmW8l9BGu2VAHCpMBA'
4+
5+
a = re.findall('^[0-9]{9}:\w+',token)
6+
print(a)
7+
a = re.findall('^[0-9]{9}:[a-zA-Z0-9]{34}',token)
8+
9+
print(a)
10+
11+
a = re.search('^[0-9]{9}:[a-zA-Z0-9]{34}',token)
12+
print(a)
13+
14+
a = re.search('^[0-9]{9}:[a-z]{34}',token)
15+
print(a)
16+
17+

Scripts/DeleteFiles.py

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
"""
2+
@Author : Nishant Ghanate
3+
@Created : 21-10-19
4+
@Tested : Windows10 x64
5+
"""
6+
7+
import os
8+
import random
9+
10+
class DeleteFiles:
11+
12+
def __init__(self):
13+
self.__files = list()
14+
15+
def scan(self,path):
16+
# print("Recursive call {}".format(path))
17+
try :
18+
for p in os.scandir(path):
19+
isDirectory = os.path.isdir(p)
20+
if isDirectory:
21+
# print('\nInside Dir = {}'.format(p.path))
22+
files = os.listdir(p.path)
23+
for f in files:
24+
l = os.path.join(p.path,f)
25+
isDirectory = os.path.isdir(l)
26+
if isDirectory:
27+
# print("\nNested Directory {} ".format(l))
28+
self.scan(l)
29+
else:
30+
self.__files.append(l)
31+
# print(l)
32+
else:
33+
# print(p.path)
34+
self.__files.append(p.path)
35+
return self.__files
36+
except Exception as e:
37+
print('Access Denied on {}' .format(p.path))
38+
return self.__files
39+
40+
def delete(self,files,extensions=None):
41+
filesRemoved = []
42+
try:
43+
for f in files:
44+
isFile = os.path.isfile(f)
45+
if isFile and extensions != None:
46+
ext = f.split('.')
47+
if ext[1] in extensions:
48+
os.remove(f)
49+
print('File removed = {} '.format(f))
50+
filesRemoved.append(f)
51+
elif isFile and extensions == None:
52+
os.remove(f)
53+
print('File removed = {} '.format(f))
54+
filesRemoved.append(f)
55+
else:
56+
print("File not found {}".format(f))
57+
filesRemoved.append(f)
58+
return filesRemoved
59+
except FileNotFoundError as e:
60+
print("File not found {}".format(e))
61+
return filesRemoved
62+
63+
64+
""" Add your file path with C:\\folders\\dolders\\ """
65+
filePath = "D:\\VirusSignature"
66+
fileExts = ['.asm' , '.byte']
67+
fileCount = 2
68+
deleteFiles = DeleteFiles()
69+
files = deleteFiles.scan(filePath)
70+
# print(files)
71+
72+
""" Option 1 . Delete all files from given path"""
73+
# for f in files:
74+
# deleteFiles.delete(f)
75+
76+
""" Option 2 . Delete all files with given extensions """
77+
# deleteFiles.delete(files,fileExts)
78+
79+
""" Option 3 . Delete all files with given extensions which has same file name"""
80+
# Delete Random Files with same file name different extension
81+
count = 0
82+
sameNames = []
83+
extCount = len(fileExts)
84+
lenFiles = len(files)
85+
86+
87+
for _ in range(fileCount):
88+
lenFiles = len(files)
89+
print("New len = {} ".format(lenFiles))
90+
n = random.randint(0,lenFiles-1)
91+
print('Random index = {}'.format(n) )
92+
f = files[n]
93+
94+
ext = f.split('.')
95+
print('\n')
96+
for e in fileExts:
97+
newFile = ext[0] + e
98+
isFile = os.path.isfile(newFile)
99+
if isFile:
100+
# print(newFile)
101+
# lenFiles = len(files)
102+
count += 1
103+
sameNames.append(newFile)
104+
else:
105+
count = 0
106+
sameNames = []
107+
break
108+
109+
if count == extCount:
110+
print(sameNames)
111+
for s in sameNames:
112+
files.remove(s)
113+
# deleteFiles.delete(s)
114+
115+
# print(files)
116+
117+
118+
119+
120+
121+
122+
123+
124+
125+

Selenium/Naukri.py

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
from selenium import webdriver
2+
from selenium.webdriver.common.keys import Keys
3+
from selenium.webdriver.support import expected_conditions as EC
4+
from selenium.webdriver.common.by import By
5+
from selenium.webdriver.support.ui import WebDriverWait
6+
7+
import urllib.request as urllib
8+
import os
9+
import time
10+
import re
11+
import logging as logger
12+
13+
from bs4 import BeautifulSoup
14+
from lxml.html import fromstring
15+
16+
class Naukri:
17+
18+
def __init__(self,driverPath,id,pwd,url):
19+
self._driverPath = driverPath
20+
self._id = id
21+
self._pwd = pwd
22+
self._url = url
23+
24+
def loadDriver(self):
25+
try:
26+
if self._driverPath is None:
27+
logger.error(" Please provide a driver path")
28+
return
29+
if self._url is None:
30+
logger.error(" Please provide a website url ")
31+
# open crome options pass --incognito add_argument
32+
chrome_options = webdriver.ChromeOptions()
33+
chrome_options.add_argument("--incognito")
34+
self.driver = webdriver.Chrome(executable_path = self._driverPath , options=chrome_options)
35+
# self.driver = webdriver.Firefox(executable_path = self._driverPath )
36+
self.driver.get(self._url)
37+
except Exception as e:
38+
logger.error(str(e))
39+
return
40+
41+
def login(self):
42+
try:
43+
if self._id and self._pwd == None :
44+
logger.error(" Please provide your email and password")
45+
return
46+
search = self.driver.find_element_by_id('usernameField')
47+
search.send_keys(self._id)
48+
search = self.driver.find_element_by_id('passwordField')
49+
search.send_keys(self._pwd)
50+
search.send_keys(Keys.RETURN)
51+
52+
except Exception as e:
53+
logger.error( str(e) )
54+
return
55+
56+
# def applyFilter(self,skill,location,exp,salary):
57+
# # Note : Selenium does not know when new page is loaded . So wait till it find element from next page
58+
# element = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.ID, "qsb-location-sugg")))
59+
# print(self.driver.current_url)
60+
# search = self.driver.find_element_by_id('qsb-location-sugg')
61+
# search.click()
62+
# search.send_keys(skill)
63+
# search = self.driver.find_element_by_id('qsb-location-sugg')
64+
# search.send_keys(location)
65+
# search = self.driver.find_element_by_id('hid_expDroope-experience')
66+
# search.send_keys(exp)
67+
# search = self.driver.find_element_by_id('hid_salaryDroope-salary')
68+
# search.send_keys(salary)
69+
# search.send_keys(Keys.RETURN)
70+
71+
# search = self.driver.find_element_by_class_name('view-all right-align')
72+
# search.click()
73+
74+
# h = self.driver.find_element_by_xpath("//div[@class=view-all.right-align']//a/@href")
75+
# print(h)
76+
77+
# self.driver.find_element_by_class_name('view-all.right-align').click()
78+
79+
def applyJobs(self):
80+
element = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.ID, "qsb-location-sugg")))
81+
s = self.driver.current_url
82+
s = s.replace('homepage' , 'recommendedjobs')
83+
self.driver.get(s)
84+
element = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, "jobTuple ")))
85+
print(self.driver.current_url)
86+
html = self.driver.page_source
87+
parser = fromstring(html)
88+
urls = parser.xpath("//a[@class='tupleLink']//@href")
89+
for u in urls :
90+
print(u)
91+
if "ambitionbox" not in u :
92+
self.driver.execute_script("window.open('"+u+"', '_self')")
93+
self.driver.implicitly_wait(5)
94+
95+
element = WebDriverWait(self.driver, 5).until(EC.presence_of_element_located((By.ID, "trig1")))
96+
if element != None:
97+
print('Applied to this : {} '.format(u))
98+
element.click()
99+
else :
100+
continue
101+
102+
103+
if __name__ == '__main__':
104+
driverPath = 'G:/Github/PythonScripts/Selenium/Driver/chromedriver.exe'
105+
# driverPath = 'G:/Github/PythonScripts/Selenium/Driver/geckodriver.exe'
106+
107+
pwd = 'passqord^'
108+
url ='https://www.naukri.com/nlogin/logout'
109+
110+
naukri = Naukri(driverPath,id,pwd,url)
111+
naukri.loadDriver()
112+
naukri.login()
113+
114+
# skill = 'python'
115+
# location = 'mumbai'
116+
# exp = 1
117+
# salary = 5
118+
# naukri.applyFilter(skill,location,exp,salary)
119+
120+
naukri.applyJobs()
121+
122+
123+
124+
125+
126+
# Input fileds : driver.clear()
127+
# id : qsb-keyskill-sugg
128+
# id : qsb-location-sugg
129+
# id : expDroope-experienceFor , hid_expDroope-experience 0 - 30 years
130+
# id : salaryDroope-salaryFor , hid_salaryDroope-salary 0 - 100 LPA
131+
# driver.find_element_by_xpath("//input[contains(@class,'view-all right-align')]").get_attribute('value')
132+
# by_xpath("//a[@class='tupleLink']//@href")
133+
# $x("//a[@class='tupleLink']")
134+
135+
136+
# print(html)
137+
# soup = BeautifulSoup(html, 'html5lib')
138+
# table = soup.findAll('a', attrs = {'class':'tupleLink'})
139+
# print(table)
140+
# for t in table:
141+
# url = t['href']
142+
# print(url)
143+
# jobLinks = self.driver.find_element_by_xpath("//a[@class='tupleLink']")

Selenium/Youtube.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def loadUrl(self):
5151
return False
5252

5353
def start(self,):
54+
driver.implicitly_wait(10)
5455
self.driver.get(self.url)
5556
# Had to write like because document.body.scrollHeight was returning 0 on youtube
5657
previous = 0

0 commit comments

Comments
 (0)