import requests
import json
import sys
import multiprocessing

#function for saving the merged state
def writeState1(state):
	print("Writing state")
	statefile = open("crawl-state.json","w")
	statefile.write(json.dumps(state))
	statefile.close()

#function for reading the first state
def getState1():
	statefile = open("crawl-state.json","r")
	state = json.loads(statefile.read())
	statefile.close()
	return state

#function for reading the second state
def getState2():
	statefile = open("crawl-state2.json","r")
	state = json.loads(statefile.read())
	statefile.close()
	return state

#read both states
results1 = getState1()
results2 = getState2()

print(len(results1))

#merge the second state into the first state
for item in results2.keys():
	if item in results1 and results1[item][1] in ["Sucess","Success"]:
		continue

	results1[item] = results2[item]
	print("merged in: "+item)

print(len(results1))

#write the first state
writeState1(results1)
