-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
207 lines (180 loc) · 7.02 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
from EPmail import EPmail
#from BusquedasEPO import*
from BusquedasSem import *
#import threading
from linkTypeform import *
from datetime import datetime
import calendar
import time
def main():
###Obtener resultados desde Typeform
name_id, mail_id, text_id = 'textfield_D85lzVq29NwK', 'email_Zqrl80iApgim', 'textarea_BiFS9A3GtmUs'
#'textfield_52850379','email_52850524','textarea_52850750'
#
#bus = list()
##enaex
#text = 'emulsion explosiva; explosivo plástico; aceite con agua; emulsificante; robusto'
#data = 'client1'
#pn='WO' #solo patentes internacionales
##Paper wallet
#text = 'metodo billetera plegable; billetera de papel;hoja rectangular sin cortes'
#data = 'client2'
#pn = None
##Timer cronos
#text = 'cronometraje deportivo; sensores RFID; sensores activos; sensores ultrasonicos'
## Deberíamos editar este mail
itext = "Hola! soy Ro, y respondo a lo que solicitaste usando las palabras ["
ftext = """
Cualquier duda por favor contacta a uno de nuestros humanos
[email protected] es uno de los mejores que conozco.
Que tengas un buen dia!"""
ferror = "Lo siento, pero tus criterios no arrojan resultados."
msubject = 'Busqueda EasyPatents'
mfrom = '[email protected]'
data = 'client'
pn = 'WO'
d = datetime.utcnow()
timestamp1 = str(calendar.timegm(d.utctimetuple()))
count = 0
while (True):
d = datetime.utcnow()
timestamp2 = str(calendar.timegm(d.utctimetuple()))
if timestamp1 == '':
content = getFormComplete(typeform_UID='ZD0bjr', until=timestamp1)
else:
content = getFormComplete(typeform_UID='ZD0bjr', since=timestamp1)
timestamp1 = timestamp2
# Hay que hacer la subrutina para responder los correos
content = getFormComplete(typeform_UID='ZD0bjr', offset=0, limit=5)
#
print(content)
nombre, mail, respuesta = getResponses(content=content, id=name_id),\
getResponses(content=content, id=mail_id), \
getResponses(content=content, id=text_id)
where = 'ab'
for k in range(len(respuesta)):
path = data + str(count)
words = getWordsText(respuesta[k])
sent = sentenceProcessing(respuesta[k])
print(sent)
cql = preProcessing(where, sent, pn)
print(cql)
gamma = 0.01
searchResponse(path, cql, words, gamma)
epm = EPmail()
fname = './' + path + '-sort.csv'
fformat = 'resp.csv'
mmessage = itext + respuesta[k] + ' ] ' + ftext
# aux = epm.send_complex_message(mail[k],mfrom,msubject,mmessage,fformat,fname)
# print(mail[k])
# print(aux)
count += 1
# epm = EPmail()
# mmessage = itext + respuesta[k]+' ] '+ferror+ftext
# aux = epm.send_simple_message(mail[k],mfrom, msubject,mmessage)
# print(mail[k])
# print(aux)
time.sleep(60)
def Abstract(client, number, country, kind):
response = abstract_helper(client, number, country, kind)
abstract = busquedaLang(response, idioma='en', type='xml')
# if abstract == None:
# aux = busquedaLang(response, idioma='ol', type='xml')
# #abstract = translateTextAuto(lengout='en',text=str(aux))
# abstract = translateText(aux)
return abstract
def abstract_helper(client, number, country, kind):
response = client.published_data(
reference_type='publication',
input=epo_ops.models.Docdb(str(number), country, kind),
endpoint='abstract',
)
return response
def HTTPstatus(status):
s = ""
if status == 200:
s = "Everything worked as expected"
if status == 400:
s = "Invalid date in query/"
if status == 403:
s = "Expired Token/Invalid Token/Token does not have access permissions/Invalid Token"
if status == 404:
s = "Type in URL/Invalid typeform ID"
if status == 429:
s = "Request limit reached"
return print("http_status = " + s)
def searchResponse(data, cql, words, gamma):
createCSV(data)
a = int(200 / 25.0)
for k in range(a):
client = initEPO()
rbegin = (k) * 25 + 1
rend = (k + 1) * 25
#try:
response = client.published_data_search(cql=cql,
range_begin=rbegin,
range_end=rend,
constituents=None)
#except:
#print("error en la respuesta epo cql incorrecta")
#print(getSoup(response).prettify())
#try:
country, number, kind = busquedaEPO(response, 'country', type='html'),\
busquedaEPO(response, 'doc-number', type='html'),\
busquedaEPO(response, 'kind', type='html')
#except:
#print("error en la respuesta epo numero de publicacion incorrecta")
abstracts = []
auxes = []
for i in range(len(country)):
abstract = Abstract(client=client,
number=number[i],
country=country[i],
kind=kind[i])
aux = country[i] + number[i] + kind[i]
if abstract == None or len(abstract) <= 1:
pass
else:
#print(abstract)
#print(type(abstract))
abstracts.append(abstract)
auxes.append(aux)
#writeCSV(data,PCAScore(words,abstract,gamma),aux,abstract)
abstracts2 = []
for e in abstracts:
if len(e) > 2:
abstracts2.append(e)
#print(type(abstracts))
#print(type(abstracts2))
#print(abstracts2)
X = thoughtobeat(words, abstracts)
#print(X)
# puntajes = PCAscore2(X)
# for i in range(len(puntajes)):
# writeCSV(data, puntajes[i], auxes[i], abstracts[i])
# path = './'+data+'.csv'
# name = './'+data+'-sort.csv'
# sortCSV(path,name)
if __name__ == "__main__":
main()
# from https://www.typeform.com/help/data-api/
# HTTP status code summary
# status
# 200
# Everything worked as expected
# 400
# Invalid date in query/
# 403
# Expired Token/Invalid Token/Token does not have access permissions/Invalid Token
# 404
# Type in URL/Invalid typeform ID
# 429
# Request limit reached
# from https://pypi.python.org/pypi/python-epo-ops-client
# When you issue a request, the response is a requests.Response object
# If response.status_code != 200 then a requests.HTTPError exception will be raised
# The following custom exceptions are raised for cases when OPS quotas are exceeded,
# they are all in the epo_ops.exceptions module and are subclasses of requests.HTTPError,
# and therefore offer the same behaviors:
# IndividualQuotaPerHourExceeded
# RegisteredQuotaPerWeekExceeded