├── README.md └── naukri.py /README.md: -------------------------------------------------------------------------------- 1 | # About 2 | This script is a hack for naukri.com apis https://www.naukri.com/. It updates the userprofile ('resume headline') at a random interval of 2 to 12 minutes 3 | 4 | # How it helps 5 | Updating the naukri.com's profile continously moves it to the top, which means more recruiters will be able to see your profile and contacts you. 6 | 7 | # How to use 8 | Python 3.6 has to installed. 9 | 10 | You have 4 options to input username and password 11 | You can select either one: 12 | 13 | 1. Hardcode your username and password on the top of the script: 14 | ``` 15 | hard_user_name= 'your_username' 16 | hard_pass_word= 'your_password' 17 | ``` 18 | 19 | 2. Or make a text file `'user_data.txt'` in the same directory and add your username and password in that. 20 | 3. Or run the script and input username and password on the prompt. 21 | 4. Or you can pass the argument like : 22 | ``` 23 | python naukri.py your_username your_password 24 | ``` 25 | Suggestions: Most preferable way must have to be adding 'user_data.txt' file and storing your username and password over there. And then simply run : 26 | ``` 27 | python naukri.py 28 | ``` 29 | 30 | Voila your are done. Until the script is running and connected to internet it will update your profile. 31 | 32 | Make sure you're connected to internet and run the script : 33 | 34 | 35 | ``` 36 | python naukri.py 37 | ``` 38 | -------------------------------------------------------------------------------- /naukri.py: -------------------------------------------------------------------------------- 1 | import re 2 | import time 3 | from datetime import datetime 4 | import os 5 | import random 6 | import sys 7 | try: 8 | import requests 9 | except ModuleNotFoundError: 10 | print('Trying to install requests module\n') 11 | os.system('pip3 install requests') 12 | finally: 13 | import requests 14 | 15 | #Hardcode the username and password here: 16 | hard_user_name = '' 17 | hard_pass_word = '' 18 | 19 | class Naukri: 20 | validated = False 21 | def __init__(self): 22 | """ Initialize 23 | 24 | Initializes the class. 25 | """ 26 | self.base_url = 'https://www.nma.mobi' 27 | self.header = {'Content-Type': 'application/json; charset=utf-8', 28 | 'clientId': 'ndr01d', 29 | 'deviceId': self.gen_random_id(), 30 | 'AppVersion': '71', 31 | 'Accept': 'application/json', 32 | 'Accept - Encoding': 'gzip', 33 | 'Accept - Charset': 'UTF - 8' 34 | } 35 | self.session = self.get_session() 36 | 37 | def get_session(self): 38 | """ Session 39 | 40 | Create a session for GET or POST. 41 | """ 42 | session = requests.Session() 43 | return session 44 | 45 | def gen_random_id(self): 46 | return ''.join(random.choice('0123456789abcdef') for _ in range(16)) 47 | 48 | def post_login(self, userName, passWord): 49 | """ Post Login Call 50 | 51 | Sign in to the server 52 | """ 53 | url = self.base_url + '/login/v2/login' 54 | json_data = {"USERNAME":userName,"ISLOGINBYEMAIL":"1","PASSWORD":passWord} 55 | 56 | login_response = self.session.post(url, json=json_data, headers=self.header) 57 | 58 | return login_response 59 | 60 | def get_dashboard(self): 61 | """ Get Dashboard 62 | 63 | Get the user details 64 | """ 65 | url = self.base_url + '/mnj/v3/dashBoard?properties=profile(isPushdownAvailable)' 66 | 67 | dash_response = self.session.get(url, headers=self.header) 68 | self.profile_id = dash_response.json().get('dashBoard').get('profileId') 69 | 70 | def get_profile(self): 71 | """ Get Profile 72 | 73 | Get the user Profile 74 | """ 75 | url = self.base_url + '/mnj/v2/user/profiles?&expand_level=2&active=1' 76 | 77 | profile_response = self.session.get(url, headers=self.header) 78 | return profile_response 79 | 80 | def update_profile(self, json_data): 81 | """ Update Profile 82 | 83 | Updates the user Profile 84 | """ 85 | url = self.base_url + '/mnj/v1/user/profiles/' + self.profile_id + '/' 86 | 87 | self.session.post(url, json=json_data, headers=self.header) 88 | 89 | def valLogin(self, userName, passWord): 90 | """Validates Login Session 91 | 92 | Validates that login was successful 93 | """ 94 | print('Validating your Credentials.........\n') 95 | print('Entered Username : ' + userName) 96 | print('Entered Password : {0}*****{1}'.format(passWord[:2], passWord[len(passWord)-2:])) 97 | login_response = self.post_login(userName, passWord) 98 | if login_response.json().get('error'): 99 | print(', '.join(list(self.find('message',login_response.json())))) 100 | self.validated = False 101 | return False 102 | 103 | else: 104 | self.validated = True 105 | self.header['Authorization'] = 'NAUKRIAUTH id=' + login_response.json().get('id') 106 | print('You are Successfully Logged in') 107 | self.get_dashboard() 108 | return True 109 | 110 | def find(self, key, dictionary): 111 | for k, v in dictionary.items(): 112 | if k == key: 113 | yield v 114 | elif isinstance(v, dict): 115 | for result in self.find(key, v): 116 | yield result 117 | elif isinstance(v, list): 118 | for d in v: 119 | for result in self.find(key, d): 120 | yield result 121 | 122 | #################################################################################################################################### 123 | 124 | 125 | def input_user_data(): 126 | users_name = '' 127 | while(True): 128 | if not clean_username(users_name): 129 | users_name = input('\nEnter your registered email of naukri.com:\n') 130 | else: 131 | user_password = clean_password(input('Enter the Password\n')) 132 | if user_password: 133 | break 134 | 135 | print('--'*40) 136 | 137 | return users_name, user_password 138 | 139 | 140 | def nested_dict(d): 141 | for k, v in d.items(): 142 | if isinstance(v, dict): 143 | nested_dict(v) 144 | else: 145 | print("{0} : {1}".format(k, v)) 146 | 147 | 148 | def clean_username(username): 149 | if username: 150 | validation = re.compile(r"[^@\s]+@[^@\s]+\.[a-zA-Z0-9]+$") 151 | if validation.match(username.strip()): 152 | return username.strip() 153 | 154 | else: 155 | print('Invalid Username') 156 | print("Must contains valid email id like : your_email@domain.extention\n") 157 | print('--' * 40) 158 | 159 | 160 | def clean_password(password): 161 | if password: 162 | return password.strip() 163 | else: 164 | print('Password cannot be blank') 165 | 166 | 167 | def clean_data(username, password): 168 | return clean_username(username), clean_password(password) 169 | 170 | 171 | def file_exists(): 172 | try: 173 | with open('user_data.txt', 'r') as data: 174 | print('Found user_data.txt file') 175 | username, password = data.readlines() 176 | return username, password 177 | 178 | except FileNotFoundError: 179 | pass 180 | 181 | except ValueError: 182 | print('File does not have valid data') 183 | print('First line must contain username and second line password like:') 184 | print(''' 185 | your_email@domain.extention 186 | your_password 187 | ''') 188 | 189 | def user_data(): 190 | #hardcode your username and password 191 | username = hard_user_name 192 | password = hard_pass_word 193 | 194 | #Or your can make a file name user_data.txt and add username and password in it. 195 | #Username must be email id 196 | #And it should come at first line 197 | #and password on the second line 198 | if os.path.isfile('user_data.txt'): 199 | try: 200 | username, password = file_exists() 201 | except TypeError: 202 | pass 203 | 204 | if clean_username(username) and clean_password(password): 205 | return clean_username(username), clean_password(password) 206 | 207 | 208 | def main(): 209 | naukri = Naukri() 210 | 211 | if len(sys.argv) > 1: 212 | if len(sys.argv) == 2: 213 | print('Password cannot be blank\n') 214 | user_info = sys.argv[1], input('Enter the password\n') 215 | else: 216 | user_info = sys.argv[1], sys.argv[2] 217 | else: 218 | user_info = user_data() 219 | 220 | if not user_info or not naukri.valLogin(*user_info): 221 | while True: 222 | user_info = input_user_data() 223 | if naukri.valLogin(*user_info): 224 | break 225 | 226 | #Validates and update the data. 227 | if naukri.validated: 228 | 229 | pro_dic = naukri.get_profile().json() 230 | find_value = list(naukri.find('resumeHeadline',pro_dic))[0] 231 | while True: 232 | print('updating...') 233 | naukri.update_profile({'resumeHeadline': find_value}) 234 | print('updated at '+str(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))) 235 | time.sleep(random.randint(120,750)) 236 | 237 | 238 | if __name__ == '__main__': 239 | main() 240 | --------------------------------------------------------------------------------