Skip to content

Instantly share code, notes, and snippets.

@bhanuraja
Last active September 11, 2019 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhanuraja/162ed3ad4c2797b41223c3c33605ef60 to your computer and use it in GitHub Desktop.
Save bhanuraja/162ed3ad4c2797b41223c3c33605ef60 to your computer and use it in GitHub Desktop.
Chegg question skipping
import requests
import time
# from quickstart import start,create_message,send_message
# service = start()
# message = create_message('me','bsureshjnv@gmail.com','chegg','Found question')
data = {'clientId':'CHGG','email':'darshanpriya0@gmail.com','password':'Trivial!123'}
url = 'https://www.chegg.com/auth/_ajax/auth/v1/login?clientId=CHGG'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36',
'Host':'www.chegg.com',
'DNT':'1'}
s = requests.Session()
#s.get(url='https://www.chegg.com/my/expertqa',headers=headers)
#page = s.get(url='https://www.chegg.com/auth?action=login',headers=headers)
# print(page.headers)
# print(page.cookies)
page1 = s.post(url=url,data=data,headers=headers)
#print(page1.text)
#page2 = s.get('https://www.chegg.com/my/expertqa',headers=headers)
#print(page2.text)
page3 = s.get('http://www.chegg.com/homework-help/expertquestion',headers=headers)
z = str(page3.text)
i = 200
skipurl = 'https://www.chegg.com/study/_ajax/expertquestion'# type post request
skip_data={'questionId':3434,'skipTime':'543','skipReason':'InsufficientKnowledge','skipSource':'skipGetNextQuestion','questionSkipSource':'d'}
while(i>0):
#time.sleep(15)
i=i-1
z = str(s.get('https://www.chegg.com/homework-help/expertquestion',headers=headers).text)
print('page is ')
print(z)
if 'Time remaining to complete the answer' in z:
print('answering question')
time.sleep(600)
elif 'Skip & Get next question' in z:
time.sleep(20)
print('question going to be skipped')
z = str(s.get('http://www.chegg.com/homework-help/expertquestion',headers=headers).text)
if 'Time remaining to complete the answer' in z:
print('question answering')
time.sleep(600)
else:
index = z.find('data-qid') + 10
end_index = index + 7
qid = z[index:end_index + 1]
skip_data['questionId']=qid
s.post(url= skipurl,data=skip_data,headers=headers)
print('skipped question')
else:
print('elsesss')
time.sleep(10)
# while(i>0):
# time.sleep(10)
# i=i-1
# if "Skip & Get next question" in z:
# print("found question")
# send_message(service,'me',message)
# time.sleep(600)
# page3 = s.get('http://www.chegg.com/homework-help/expertquestion', headers=headers)
# z = str(page3.text)
# else:
# page3 = s.get('http://www.chegg.com/homework-help/expertquestion', headers=headers)
# z = str(page3.text)
from __future__ import print_function
import base64
import pickle
import os.path
from email.mime.text import MIMEText
from googleapiclient import errors
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
# If modifying these scopes, delete the file token.pickle.
#SCOPES = ['https://www.googleapis.com/auth/gmail.readonly']
SCOPES = ['https://www.googleapis.com/auth/gmail.send']
def main():
"""Shows basic usage of the Gmail API.
Lists the user's Gmail labels.
"""
creds = None
# The file token.pickle stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists('token.pickle'):
with open('token.pickle', 'rb') as token:
creds = pickle.load(token)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', SCOPES)
creds = flow.run_local_server()
# Save the credentials for the next run
with open('token.pickle', 'wb') as token:
pickle.dump(creds, token)
service = build('gmail', 'v1', credentials=creds)
# Call the Gmail API
results = service.users().labels().list(userId='me').execute()
labels = results.get('labels', [])
#send_message(service,'me',create_message('bhanuraja1997@gmail.com','movmmk@gmail.com','dfs','dfcdfdcd'))
if not labels:
print('No labels found.')
else:
print('Labels:')
for label in labels:
print(label['name'])
if __name__ == '__main__':
main()
def start():
creds = None
if os.path.exists('token.pickle'):
with open('token.pickle', 'rb') as token:
creds = pickle.load(token)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', SCOPES)
creds = flow.run_local_server()
# Save the credentials for the next run
with open('token.pickle', 'wb') as token:
pickle.dump(creds, token)
service = build('gmail', 'v1', credentials=creds)
return service
def create_message(sender, to, subject, message_text):
"""Create a message for an email.
Args:
sender: Email address of the sender.
to: Email address of the receiver.
subject: The subject of the email message.
message_text: The text of the email message.
Returns:
An object containing a base64url encoded email object.
"""
message = MIMEText(message_text)
message['to'] = to
message['from'] = sender
message['subject'] = subject
return {'raw': str(base64.urlsafe_b64encode(message.as_bytes()),'utf-8')}
def send_message(service, user_id, message):
"""Send an email message.
Args:
service: Authorized Gmail API service instance.
user_id: User's email address. The special value "me"
can be used to indicate the authenticated user.
message: Message to be sent.
Returns:
Sent Message.
"""
try:
message = (service.users().messages().send(userId=user_id, body=message)
.execute())
print ('Message Id: %s' % message['id'])
return message
except errors.HttpError as error:
print ('An error occurred: %s' % error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment