Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import print_function
- from pprint import pprint
- from googleapiclient import discovery
- import httplib2
- import os
- from apiclient import discovery
- from oauth2client import client
- from oauth2client import tools
- from oauth2client.file import Storage
- import time, os
- from selenium import webdriver
- from selenium.webdriver.common.keys import Keys
- from selenium.webdriver.common.by import By
- from selenium.webdriver.common.service import Service
- try:
- import argparse
- flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
- except ImportError:
- flags = None
- # If modifying these scopes, delete your previously saved credentials
- # at ~/.credentials/sheets.googleapis.com-python-quickstart.json
- SCOPES = ['https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/drive.file', 'https://www.googleapis.com/auth/drive.readonly', 'https://www.googleapis.com/auth/spreadsheets', 'https://www.googleapis.com/auth/spreadsheets.readonly']
- CLIENT_SECRET_FILE = 'client_secret.json'
- APPLICATION_NAME = 'Digipanel Bot'
- def get_credentials():
- """Gets valid user credentials from storage.
- If nothing has been stored, or if the stored credentials are invalid,
- the OAuth2 flow is completed to obtain the new credentials.
- Returns:
- Credentials, the obtained credential.
- """
- home_dir = os.path.expanduser('~')
- credential_dir = os.path.join(home_dir, '.credentials')
- if not os.path.exists(credential_dir):
- os.makedirs(credential_dir)
- credential_path = os.path.join(credential_dir, 'sheets.googleapis.com-DigipanelBot.json')
- store = Storage(credential_path)
- credentials = store.get()
- if not credentials or credentials.invalid:
- flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
- flow.user_agent = APPLICATION_NAME
- if flags:
- credentials = tools.run_flow(flow, store, flags)
- else: # Needed only for compatibility with Python 2.6
- credentials = tools.run(flow, store)
- print('Storing credentials to ' + credential_path)
- return credentials
- def start():
- log_name = input('Enter Username: ')
- log_pass = input('Enter Password: ')
- driver = open_chrome()
- print()
- login(log_name, log_pass, driver)
- def open_chrome():
- print('Opening Chrome...')
- driver = webdriver.Chrome()
- driver.get("http://rto.digitals.pw/")
- return driver
- def login(log_name, log_pass, driver):
- username = driver.find_element_by_name("username")
- username.clear()
- username.send_keys(log_name)
- username = driver.find_element_by_name("password")
- username.clear()
- username.send_keys(log_pass)
- time.sleep(1)
- driver.find_element_by_name("login").click()
- if "login" in driver.current_url:
- print("Incorrect Username or Password, please try again.")
- print()
- log_name = input('Enter Username: ')
- log_pass = input('Enter Password: ')
- login(log_name, log_pass, driver)
- else:
- search(driver)
- def search(driver):
- driver.get("http://rto.digitals.pw/police/interpol/kavala")
- search = driver.find_element_by_xpath("//button[10]")
- search.click()
- print("Gathering Data...")
- time.sleep(15)
- complete = False
- count = 1
- data = [[],[]]
- lastNames = []
- while complete == False:
- try:
- search = driver.find_element_by_xpath("//tr[{0}]/td[1]".format(count)).text
- data[0].append(search)
- lastName = driver.find_element_by_xpath("//tr[{0}]/td[4]".format(count)).text
- lastNames.append(lastName)
- lastActive = driver.find_element_by_xpath("//tr[{0}]/td[5]".format(count)).text
- lastActive = lastActive[2:13]
- data[1].append(lastActive)
- count += 1
- except:
- complete = True
- sync(data, lastNames)
- def sync(data, lastNames):
- credentials = get_credentials()
- service = discovery.build('sheets', 'v4', credentials=credentials)
- #ANY EDITS, CHANGE SHEET ID!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- spreadsheet_id = '19MN7jyO6RzGAMFIjv65Oh6Z7BR2dxNYouvaml7y44xQ'
- range_ = 'Kavala!B:B'
- value_render_option = 'FORMATTED_VALUE'
- date_time_render_option = 'SERIAL_NUMBER'
- request = service.spreadsheets().values().get(spreadsheetId=spreadsheet_id, range=range_, valueRenderOption=value_render_option, dateTimeRenderOption=date_time_render_option)
- response = request.execute()
- count = 1
- print("Updating Interpol...")
- for i in response['values']:
- if "Meeting" in str(i):
- break
- else:
- if len(i) > 0 and 'Vacant' not in i:
- try:
- index = data[0].index(i[0])
- if 'Police' in lastNames[index]:
- value = data[1][index]
- values = [[str(value[1:])]]
- body = {'values' : values}
- request = service.spreadsheets().values().update(spreadsheetId=spreadsheet_id, range='Kavala!N'+str(count),
- valueInputOption='RAW', body=body).execute()
- else:
- pass
- except:
- pass
- else:
- pass
- count += 1
- print("Complete.")
- input()
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement