Skip to content

Commit

Permalink
json example
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximShepelev committed Oct 23, 2018
1 parent 1a1e30c commit f37bbd7
Show file tree
Hide file tree
Showing 284 changed files with 96,984 additions and 96,179 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
token.txt

json/venv
12 changes: 12 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

692 changes: 692 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

12 changes: 0 additions & 12 deletions algorithm.txt

This file was deleted.

129 changes: 109 additions & 20 deletions json/parse.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,127 @@
#!/usr/bin/python
import json
import pprint
import openpyxl
from datetime import datetime
from tkinter import *
import random
from tkinter import Tk, Label, Button, Entry, StringVar, DISABLED, NORMAL, END, W, E


class Calculator:

def __init__(self, master):
self.master = master
master.title("Calculator")

self.total = 0
self.entered_number = 0

self.total_label_text = IntVar()

#vcmd = master.register(self.validate) # we have to wrap the command
self.labelT = Label(master, text="Token:")
self.labelF = Label(master, text="File Path:")
self.entry1 = Entry(master) #, validate="key", validatecommand=(vcmd, '%P'))
self.entry2 = Entry(master)

self.ok_button = Button(master, text="OK")
self.choose_button = Button(master, text="Choose file", command=lambda: self.choose())
#self.add_button = Button(master, text="+", command=lambda: self.update("add"))
#self.subtract_button = Button(master, text="-", command=lambda: self.update("subtract"))
#self.reset_button = Button(master, text="Reset", command=lambda: self.update("reset"))

# LAYOUT

self.entry1.grid(row=1, column=1, columnspan=3, sticky=W+E)
self.entry2.grid(row=2, column=1, columnspan=3, sticky=W + E)
self.labelT.grid(row=1, column=0)
self.labelF.grid(row=2, column=0)

self.ok_button.grid(row=3, column=0)
self.choose_button.grid(row=2, column=5)

def choose(self):
return True

def ok(self):
token = self.entry1.get()
filename = self.entry2.get()

def update(self, method):
if method == "add":
self.total += self.entered_number
elif method == "subtract":
self.total -= self.entered_number
else: # reset
self.total = 0

self.total_label_text.set(self.total)
self.entry.delete(0, END)

root = Tk()
my_gui = Calculator(root)
root.mainloop()

print(my_gui.token)


#root = Tk()
#d = MyDialog(root)
#root.mainloop()

# Output
def output_to_excel():
now = datetime.now()
output_file = 'results_' + now.strftime("%Y-%m-%d_%H:%M:%S") + '.xlsx'
wb = openpyxl.Workbook()
engine = "g_us"
sheetname = "Top_keyword" + engine
wb.create_sheet(sheetname)
sheet = wb.get_sheet_by_name(sheetname)

sheet.cell(row=1 + 1, column=1).value = 'Keyword'
sheet.cell(row=1, column=1).font = openpyxl.styles.Font(bold=True)
sheet.cell(row=1, column=2).value = 'Query engine'
sheet.cell(row=1, column=2).font = openpyxl.styles.Font(bold=True)
sheet.cell(row=1, column=3).value = 'Response Message'
sheet.cell(row=1, column=3).font = openpyxl.styles.Font(bold=True)
sheet.cell(row=1, column=4).value = 'Queries count'
sheet.cell(row=1, column=4).font = openpyxl.styles.Font(bold=True)
sheet.cell(row=1, column=5).value = 'Found Results'
sheet.cell(row=1, column=5).font = openpyxl.styles.Font(bold=True)
sheet.cell(row=1, column=6).value = 'Domains'
sheet.cell(row=1, column=6).font = openpyxl.styles.Font(bold=True)
sheet.cell(row=1, column=7).value = 'Full URLs'
sheet.cell(row=1, column=7).font = openpyxl.styles.Font(bold=True)
# ws = wb.activate()

wb.save(output_file)

file = open("json.example","r")
#print(file.read())

jsondata = json.loads(file.read())
# print(jsondata)

# output to file example
# output = open("json.example2", "w")
# pprint.pprint(jsondata, output)

# left_lines = jsondata["left_lines"]
# print(left_lines)
# easier than above

domains = ""
# print("\ngetting all domains:")
for item in jsondata['result']['top']:
domains += item.get("domain") + ","

# print(domains)

urls = ""
# print("\ngetting all URLS:")
for item in jsondata['result']['top']:
urls += item.get("url") + ","

# print(urls)

print(jsondata['left_lines'])
print(jsondata['result']['results'])
# print(jsondata['result']['top'][0]['domain'] + ", " + jsondata['result']['top'][0]['url'])
print("found_domains:" + domains)
print("found_urls:" + urls)
print()
print(len(jsondata['result']['top']))
if jsondata['status_code'] == 200:
print("status code is 200:")
print(jsondata['status_code'])

print(jsondata['status_msg'])
status_msg = "%i"% (jsondata['status_code']) + ", " + jsondata['status_msg']
print(status_msg)



# Output
# output_to_excel()
Original file line number Diff line number Diff line change
@@ -1 +1 @@

Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "10.0.1"
__version__ = "10.0.1"
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
from __future__ import absolute_import

import os
import sys

# If we are running from a wheel, add the wheel to sys.path
# This allows the usage python pip-*.whl/pip install pip-*.whl
if __package__ == '':
# __file__ is pip-*.whl/pip/__main__.py
# first dirname call strips of '/__main__.py', second strips off '/pip'
# Resulting path is the name of the wheel itself
# Add that to sys.path so we can import pip
path = os.path.dirname(os.path.dirname(__file__))
sys.path.insert(0, path)

from pip._internal import main as _main # noqa

if __name__ == '__main__':
sys.exit(_main())
from __future__ import absolute_import

import os
import sys

# If we are running from a wheel, add the wheel to sys.path
# This allows the usage python pip-*.whl/pip install pip-*.whl
if __package__ == '':
# __file__ is pip-*.whl/pip/__main__.py
# first dirname call strips of '/__main__.py', second strips off '/pip'
# Resulting path is the name of the wheel itself
# Add that to sys.path so we can import pip
path = os.path.dirname(os.path.dirname(__file__))
sys.path.insert(0, path)

from pip._internal import main as _main # noqa

if __name__ == '__main__':
sys.exit(_main())
Loading

0 comments on commit f37bbd7

Please sign in to comment.