inital = transfer git to git2
This commit is contained in:
+28
@@ -0,0 +1,28 @@
|
||||
.DS_Store
|
||||
node_modules
|
||||
.history
|
||||
/dist
|
||||
/html
|
||||
|
||||
|
||||
# local env files
|
||||
.env.local
|
||||
.env.*.local
|
||||
/__pycache__
|
||||
|
||||
# Log files
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# Editor directories and files
|
||||
.history
|
||||
.idea
|
||||
.vscode
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
*.rar
|
||||
*.zip
|
||||
@@ -0,0 +1,112 @@
|
||||
import json
|
||||
import requests
|
||||
from config_base import *
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from html import escape
|
||||
import json
|
||||
from decimal import Decimal
|
||||
import datetime
|
||||
|
||||
|
||||
from config_base import *
|
||||
from general_functions import *
|
||||
|
||||
# موقت
|
||||
# این برنامه موقتا بخاطر اصلاح داده اجرا شد، اگر از ابتدا انتقال داده انجام شود این بخش خودکار انجام خواهد شد
|
||||
|
||||
cursor, cnxn = create_cursor()
|
||||
|
||||
# Does quasi the same things as json.loads from here: https://pypi.org/project/dynamodb-json/
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, Decimal):
|
||||
return float(obj)
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
||||
#نکته : برای مقررات هیچ موردی نبود که جدولی باشد
|
||||
query = '''
|
||||
SELECT s.ID as sectionId
|
||||
,isnull(lss2.CAPTION,'') as qanon_etebar -- lwLawSectionStatus_table: ... منسوخه، معتبر، اصلاحی، موقت و
|
||||
FROM [Qavanin].[dbo].[lwSection] s
|
||||
left join lwLaw l on s.F_LWLAWID = l.ID
|
||||
left join lwLawSectionStatus lss2 on lss2.id= l.[F_CMBASETABLEID_LASTSTATUS]
|
||||
where l.ISLAW = 1
|
||||
|
||||
|
||||
'''
|
||||
|
||||
cursor.execute(query)
|
||||
|
||||
|
||||
url = BASE_URL + "repo/majles/section/multi/update"
|
||||
dict_topic = json.loads(open("list_LWTopic.json").read())
|
||||
|
||||
headers = HEADERS
|
||||
|
||||
bulk_count = 0
|
||||
bulk_data = []
|
||||
previd = ''
|
||||
ref_state_array = []
|
||||
|
||||
t1= datetime.datetime.now()
|
||||
print(t1)
|
||||
i = 0
|
||||
while 1:
|
||||
# print(i)
|
||||
i=i+1
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
|
||||
# if i > 3:
|
||||
# break
|
||||
# print(row.sectionId)
|
||||
|
||||
# try:
|
||||
# soup = BeautifulSoup(row.sectionText, "html.parser")
|
||||
# text = soup.get_text("\n", strip=True)
|
||||
# # text = removeHtmlNoTableTag(row.sectionText) # خطا داره
|
||||
# except Exception as e:
|
||||
# text = row.sectionText
|
||||
|
||||
# text = normalYehKe(text)
|
||||
|
||||
eid='qs'+ str(row.sectionId)
|
||||
|
||||
qanon_etebar = ''
|
||||
if row.qanon_etebar :
|
||||
qanon_etebar = row.qanon_etebar
|
||||
|
||||
data={
|
||||
'id' : eid,
|
||||
'qanon_etebar' : qanon_etebar
|
||||
}
|
||||
|
||||
if bulk_count > 100:
|
||||
print('=' * 10 )
|
||||
print(str(i)+ ', id=' + eid)
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
bulk_data = []
|
||||
bulk_count =0
|
||||
# print(response.text)
|
||||
#print(row.txt)
|
||||
|
||||
bulk_data.append(data)
|
||||
bulk_count +=1
|
||||
|
||||
|
||||
print(bulk_count)
|
||||
if bulk_count >= 1:
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
print(response)
|
||||
# print(response.text )
|
||||
|
||||
cursor.close()
|
||||
cnxn.close()
|
||||
print('end success')
|
||||
t2= datetime.datetime.now()
|
||||
print(t2-t1)
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
import json
|
||||
import requests
|
||||
from config_base import *
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from html import escape
|
||||
import json
|
||||
from decimal import Decimal
|
||||
import datetime
|
||||
|
||||
|
||||
from config_base import *
|
||||
from general_functions import *
|
||||
|
||||
# موقت
|
||||
# این برنامه موقتا بخاطر اصلاح داده اجرا شد، اگر از ابتدا انتقال داده انجام شود این بخش خودکار انجام خواهد شد
|
||||
|
||||
cursor, cnxn = create_cursor()
|
||||
|
||||
# Does quasi the same things as json.loads from here: https://pypi.org/project/dynamodb-json/
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, Decimal):
|
||||
return float(obj)
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
||||
#نکته : برای مقررات هیچ موردی نبود که جدولی باشد
|
||||
query = '''
|
||||
SELECT s.ID as sectionId
|
||||
,isnull(lss2.CAPTION,'') as qanon_etebar -- lwLawSectionStatus_table: ... منسوخه، معتبر، اصلاحی، موقت و
|
||||
FROM [Qavanin].[dbo].[lwSection] s
|
||||
left join lwLaw l on s.F_LWLAWID = l.ID
|
||||
left join lwLawSectionStatus lss2 on lss2.id= l.[F_CMBASETABLEID_LASTSTATUS]
|
||||
where l.[ISREGULATION] = 1
|
||||
|
||||
|
||||
'''
|
||||
|
||||
cursor.execute(query)
|
||||
|
||||
|
||||
url = BASE_URL + "repo/majles/rgsection/multi/update"
|
||||
dict_topic = json.loads(open("list_LWTopic.json").read())
|
||||
|
||||
headers = HEADERS
|
||||
|
||||
bulk_count = 0
|
||||
bulk_data = []
|
||||
previd = ''
|
||||
ref_state_array = []
|
||||
|
||||
t1= datetime.datetime.now()
|
||||
print(t1)
|
||||
i = 0
|
||||
while 1:
|
||||
# print(i)
|
||||
i=i+1
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
|
||||
# if i > 3:
|
||||
# break
|
||||
# print(row.sectionId)
|
||||
|
||||
# try:
|
||||
# soup = BeautifulSoup(row.sectionText, "html.parser")
|
||||
# text = soup.get_text("\n", strip=True)
|
||||
# # text = removeHtmlNoTableTag(row.sectionText) # خطا داره
|
||||
# except Exception as e:
|
||||
# text = row.sectionText
|
||||
|
||||
# text = normalYehKe(text)
|
||||
|
||||
eid='qs'+ str(row.sectionId)
|
||||
|
||||
qanon_etebar = ''
|
||||
if row.qanon_etebar :
|
||||
qanon_etebar = row.qanon_etebar
|
||||
|
||||
data={
|
||||
'id' : eid,
|
||||
'qanon_etebar' : qanon_etebar
|
||||
}
|
||||
|
||||
if bulk_count > 500:
|
||||
print('=' * 10 )
|
||||
print(str(i)+ ', id=' + eid)
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
bulk_data = []
|
||||
bulk_count =0
|
||||
# print(response.text)
|
||||
#print(row.txt)
|
||||
|
||||
bulk_data.append(data)
|
||||
bulk_count +=1
|
||||
|
||||
|
||||
print(bulk_count)
|
||||
if bulk_count >= 1:
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
print(response)
|
||||
# print(response.text )
|
||||
|
||||
cursor.close()
|
||||
cnxn.close()
|
||||
print('end success')
|
||||
t2= datetime.datetime.now()
|
||||
print(t2-t1)
|
||||
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
import requests
|
||||
import json
|
||||
|
||||
from config_base import *
|
||||
from general_functions import *
|
||||
|
||||
cursor, cnxn = create_cursor()
|
||||
|
||||
# -----------------------------------------------------------------
|
||||
|
||||
|
||||
ADD_LIST_ROUTE = "project/add"
|
||||
ADD_ITEM_ROUTE = "subject/add"
|
||||
TITLE = "موضوعات درختی قانون"
|
||||
TYPE = 3
|
||||
ADD_LIST_QUERY = {"title": TITLE, "type": TYPE, "item_state": 1}
|
||||
GET_H = lambda x: x["HIERARCHY"]
|
||||
GET_F = lambda x: x["F_PARENTID"]
|
||||
|
||||
|
||||
ADD_LIST_QUERY = {
|
||||
"title": TITLE,
|
||||
"type": 3,
|
||||
"item_state": 1,
|
||||
"ispublic" : 1,
|
||||
}
|
||||
|
||||
# requests.post(BASE_URL + 'list/' + ADD_LIST_ROUTE, data=ADD_LIST_QUERY, headers = HEADERS)
|
||||
projectid = 1
|
||||
|
||||
EXAMPLE_ADD_ITEM_QUERY = {
|
||||
"title": "",
|
||||
"projectid": projectid,
|
||||
"listtype": 0,
|
||||
"parent": 0,
|
||||
}
|
||||
|
||||
|
||||
|
||||
query = """select * from dbo.lwtopic"""
|
||||
cursor.execute(query)
|
||||
|
||||
|
||||
result = []
|
||||
|
||||
while True:
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
|
||||
HIERARCHY = row.HIERARCHY
|
||||
HIERARCHY = HIERARCHY.split(".")[-2]
|
||||
HIERARCHY = HIERARCHY.rjust(3, "0")
|
||||
|
||||
result.append(
|
||||
{
|
||||
"ID": int(row.ID),
|
||||
"CODE": row.CODE,
|
||||
"CAPTION": row.CAPTION,
|
||||
"F_PARENTID": int(row.F_PARENTID) if row.F_PARENTID else 0,
|
||||
"HIERARCHY": HIERARCHY,
|
||||
}
|
||||
)
|
||||
# result = sorted(result, key=GET_F)
|
||||
result = sorted(result, key=GET_H)
|
||||
|
||||
|
||||
childs = {}
|
||||
IDS_DICT = {}
|
||||
|
||||
def insert(rows):
|
||||
remains =[]
|
||||
for row in rows:
|
||||
number = 1
|
||||
try:
|
||||
F_PARENTID = row["F_PARENTID"]
|
||||
except KeyError:
|
||||
F_PARENTID = -1
|
||||
print('*'*20)
|
||||
print(row)
|
||||
print('#'*20)
|
||||
continue
|
||||
|
||||
# try:
|
||||
if F_PARENTID == 0:
|
||||
parent = 0
|
||||
elif str(F_PARENTID) in IDS_DICT:
|
||||
parent = IDS_DICT[str(F_PARENTID)]['id']
|
||||
else:
|
||||
print(F_PARENTID)
|
||||
print(IDS_DICT)
|
||||
print(row)
|
||||
break
|
||||
remains.append(row)
|
||||
continue
|
||||
|
||||
# except KeyError:
|
||||
# print('error')
|
||||
# print(row)
|
||||
# continue
|
||||
|
||||
if parent in childs:
|
||||
number = childs[parent] + 1
|
||||
childs[parent] = number
|
||||
|
||||
ADD_ITEM_QUERY = {
|
||||
"title": row["CAPTION"],
|
||||
"projectid": projectid,
|
||||
"otherid": row["ID"],
|
||||
"meta": row["CODE"],
|
||||
"childorder": number,
|
||||
"listtype": 0,
|
||||
"parent": parent,
|
||||
}
|
||||
result = requests.post(BASE_URL + 'list/' + ADD_ITEM_ROUTE, data=ADD_ITEM_QUERY, headers=HEADERS)
|
||||
|
||||
New_ID = json.loads(result.text)["data"][0]["id"]
|
||||
print(str(row["ID"]) + '=' + str(New_ID))
|
||||
IDS_DICT[str(row["ID"])] = {"id" : int(New_ID), 'title': row["CAPTION"]}
|
||||
|
||||
return remains
|
||||
|
||||
remains = insert(result)
|
||||
# print(IDS_DICT)
|
||||
|
||||
count = 1
|
||||
while remains.__len__() > 0 and count < 2:
|
||||
print('##################' + str(count))
|
||||
print( remains.__len__() )
|
||||
remains = insert(remains)
|
||||
# print(IDS_DICT)
|
||||
count = count + 1
|
||||
|
||||
with open("list_LWTopic.json", 'w') as file:
|
||||
file.write(json.dumps(IDS_DICT))
|
||||
@@ -0,0 +1,113 @@
|
||||
import pyodbc
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from html import escape
|
||||
import sys
|
||||
import json
|
||||
from decimal import Decimal
|
||||
|
||||
from general_functions import *
|
||||
cursor = create_cursor()
|
||||
|
||||
#Does quasi the same things as json.loads from here: https://pypi.org/project/dynamodb-json/
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, Decimal):
|
||||
return float(obj)
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
||||
|
||||
query = ''' SELECT l1.[ID] as F_LWSECTIONID1
|
||||
,l1.[F_LWLAWID] as F_LWLAWID1
|
||||
,l1.F_LWPHASEID as F_LWPHASEID1
|
||||
,l1.[F_LWSECTIONID_REPLACED] as F_LWSECTIONID2
|
||||
,l3.SECTIONTEXT
|
||||
,l4.F_LWLAWID_EFFECTIVE as F_LWLAWID2
|
||||
,l4.F_LWPHASEID_EFFECTIVE as F_LWPHASEID2
|
||||
FROM [AIPLawDCIT].[dbo].[lwsection] l1
|
||||
left join [AIPLawDCIT].[dbo].[lwsection] l2 on l1.F_LWSECTIONID_REPLACED = l2.id
|
||||
left join lwsectionlog l3 on l1.id=l3.F_LWSECTIONID
|
||||
left join lwlawchange l4 on l1.[F_LWLAWCHANGEID]=l4.id
|
||||
left join lwphase l6 on l4.F_LWLAWID_EFFECTIVE = l6.id
|
||||
where l1.[F_LWSECTIONID_REPLACED] is not null
|
||||
order by l1.F_LWLAWID'''
|
||||
|
||||
|
||||
cursor.execute(query)
|
||||
|
||||
|
||||
url = "https://api.tavasi.ir/repo/majles/section/add"
|
||||
url_relation = "https://api.tavasi.ir/relation/main/add"
|
||||
|
||||
headers = HEADERS
|
||||
|
||||
headers2 = {
|
||||
"Accept": ACCEPT,
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
"Authorization": TOKEN,
|
||||
}
|
||||
|
||||
rel_id_replaced = 100
|
||||
rel_id_effective = 102
|
||||
|
||||
|
||||
i = 1
|
||||
while 1:
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
print(str(i)+ ', qanonid='+str(row.F_LWLAWID1) + ', id=' + str(row.F_LWSECTIONID1))
|
||||
i=i+1
|
||||
|
||||
if row.F_LWLAWID2 is not None and str(row.F_LWLAWID2) != '' :
|
||||
payload = {
|
||||
"check_exist": 1,
|
||||
"service_id1": 'repo',
|
||||
"entity_type1": 'mqanon',
|
||||
"entity_id1": 'mj_mtaghnin_'+ str(row.F_LWLAWID2),
|
||||
"relation_id": rel_id_effective,
|
||||
"service_id2": 'repo',
|
||||
"entity_type2": 'mqanon',
|
||||
"entity_id2": 'mj_mtaghnin_'+ str(row.F_LWLAWID1),
|
||||
}
|
||||
response = requests.request("POST", url_relation, headers=headers2, data=payload)
|
||||
print(response)
|
||||
|
||||
|
||||
payload = {
|
||||
"check_exist": 0,
|
||||
"service_id1": 'repo',
|
||||
"entity_type1": 'mqsection',
|
||||
"entity_id1": 'mj_mq_section_'+ str(row.F_LWSECTIONID2),
|
||||
"relation_id": rel_id_replaced,
|
||||
"service_id2": 'repo',
|
||||
"entity_type2": 'mqsection',
|
||||
"entity_id2": 'mj_mq_section_'+ str(row.F_LWSECTIONID1),
|
||||
}
|
||||
response = requests.request("POST", url_relation, headers=headers2, data=payload)
|
||||
print(response)
|
||||
|
||||
|
||||
|
||||
# if row.SECTIONTEXT is not None and str(row.SECTIONTEXT) != '' :
|
||||
# eid = 'mj_mq_section_'+ str(row.F_LWSECTIONID2)
|
||||
# new_content = row.SECTIONTEXT
|
||||
# soup = BeautifulSoup(new_content, "html.parser")
|
||||
# text = soup.get_text("\n", strip=True)
|
||||
# content_len = text.__len__()
|
||||
|
||||
# data={
|
||||
# 'id':eid,
|
||||
# 'content': new_content,
|
||||
# 'content_len': content_len,
|
||||
# 'ref_content':escape(new_content)
|
||||
# }
|
||||
|
||||
# payload = json.dumps(data, cls=JSONEncoder) #Works!
|
||||
# response = requests.request("POST", url, headers=headers, data=payload)
|
||||
# result = json.loads( response )
|
||||
# # result["meta"][0]["1"]
|
||||
|
||||
cursor.close()
|
||||
cnxn.close()
|
||||
print('end success')
|
||||
Binary file not shown.
@@ -0,0 +1,26 @@
|
||||
import pyodbc
|
||||
|
||||
TOKEN = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2OTM5MDgzMDksImp0aSI6IjZDREM2UjB4ZFh2Y0hMUzBmdTVUQnpjZ1lLZHNMOXdEIiwiaXNzIjoiaHR0cHM6XC9cL2NwLmhhbWZhaG1pLmlyIiwiZXhwIjoxNjk1MjA4MzA4LCJhdWQiOiJodHRwczpcL1wvY3AuaGFtZmFobWkuaXIiLCJkYXRhIjp7ImlkIjoyLCJmaXJzdF9uYW1lIjoiXHUwNjJkXHUwNjQ1XHUwNmNjXHUwNjJmIiwibGFzdF9uYW1lIjoiXHUwNjM1XHUwNjQxXHUwNjI3XHUwNmNjXHUwNmNjIiwiZW1haWwiOiJzYWZhZWkuaGFtaWRAZ21haWwuY29tIiwidXNlcm5hbWUiOiJoc2FmYWVpIiwidXNlcl9sZXZlbCI6Mn19.soDo9t8FtinMamONlivJFGEVRLHOtjBOg5gzt55QVzg"
|
||||
ACCEPT = "application/json"
|
||||
HEADERS = {"Authorization": TOKEN, "Accept": ACCEPT}
|
||||
|
||||
def create_cursor():
|
||||
server = "DESKTOP-ENVCI85"
|
||||
database = "AIPLawDCIT"
|
||||
username = "Mofid3"
|
||||
password = "12345"
|
||||
|
||||
# ENCRYPT defaults to yes starting in ODBC Driver SQL Server. It's good to always specify ENCRYPT=yes on the client side to avoid MITM attacks.
|
||||
cnxn = pyodbc.connect(
|
||||
"DRIVER={SQL Server};SERVER="
|
||||
+ server
|
||||
+ ";DATABASE="
|
||||
+ database
|
||||
+ ";Trusted_Connection=yes;UID="
|
||||
+ username
|
||||
+ ";PWD="
|
||||
+ password
|
||||
)
|
||||
# cnxn = pyodbc.connect('DSN=sqldsn;')
|
||||
cursor = cnxn.cursor()
|
||||
return cursor
|
||||
@@ -0,0 +1,56 @@
|
||||
import requests
|
||||
import json
|
||||
|
||||
from config_base import *
|
||||
from general_functions import *
|
||||
|
||||
|
||||
# موقت
|
||||
# این برنامه موقتا بخاطر اصلاح داده اجرا شد، اگر از ابتدا انتقال داده انجام شود این بخش خودکار انجام خواهد شد
|
||||
|
||||
|
||||
cursor, cnxn = create_cursor()
|
||||
|
||||
# -----------------------------------------------------------------
|
||||
|
||||
|
||||
ADD_ITEM_ROUTE = "subject/edit"
|
||||
TYPE = 3
|
||||
GET_H = lambda x: x["HIERARCHY"]
|
||||
GET_F = lambda x: x["F_PARENTID"]
|
||||
|
||||
|
||||
projectid = 3
|
||||
|
||||
EXAMPLE_ADD_ITEM_QUERY = {
|
||||
"title": "",
|
||||
"projectid": projectid,
|
||||
"listtype": 0,
|
||||
"parent": 0,
|
||||
}
|
||||
|
||||
|
||||
|
||||
query = """select * from dbo.lwtopic"""
|
||||
cursor.execute(query)
|
||||
|
||||
|
||||
result = []
|
||||
|
||||
while True:
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
|
||||
ADD_ITEM_QUERY = {
|
||||
"projectid": projectid,
|
||||
"otherid": row.ID,
|
||||
"meta": row.CODE,
|
||||
}
|
||||
result = requests.post(BASE_URL + 'list/' + ADD_ITEM_ROUTE, data=ADD_ITEM_QUERY, headers=HEADERS)
|
||||
print(str(row.ID))
|
||||
# result = sorted(result, key=GET_F)
|
||||
result = sorted(result, key=GET_H)
|
||||
|
||||
|
||||
print('finish')
|
||||
@@ -0,0 +1,191 @@
|
||||
import json
|
||||
import requests
|
||||
from config_base import *
|
||||
import pyodbc
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from html import escape
|
||||
import json
|
||||
from decimal import Decimal
|
||||
import datetime
|
||||
import time
|
||||
import sys
|
||||
import traceback
|
||||
import re
|
||||
|
||||
from config_base import *
|
||||
from general_functions import *
|
||||
|
||||
|
||||
cursor, cnxn = create_cursor()
|
||||
|
||||
#Does quasi the same things as json.loads from here: https://pypi.org/project/dynamodb-json/
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, Decimal):
|
||||
return float(obj)
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
||||
|
||||
query = '''
|
||||
SELECT
|
||||
l1.[ID] as Id
|
||||
,l1.[CAPTION] as title
|
||||
--,[F_LWBASETABLEID_LAWTYPE]
|
||||
,l1.[ISLAW] -- قانون
|
||||
,l1.[ISREGULATION] -- مقرره
|
||||
,isnull(l1.APPROVEDATE,'') as aproveDate -- تاریخ تصویب
|
||||
,isnull(l1.EXPIREDATE,'') as expireDate -- تاریخ انقضا
|
||||
--,[F_LWBASETABLEID_CLASSIFICATION]
|
||||
,[RULENO]
|
||||
,[LAWNO]
|
||||
--,[F_CMBASETABLEID_LASTSTATUS]
|
||||
,lss.CAPTION as qanon_etebar
|
||||
,cbt.CAPTION as lawType
|
||||
,(
|
||||
SELECT top (1) p3.CAPTION
|
||||
FROM [lwPhase] p1
|
||||
left join [lwApprover] p2 on p1.ID=p2.F_LWPHASEID
|
||||
left join cmOrganization p3 on p2.F_CMORGANIZATIONID = p3.id
|
||||
where l1.ID = p1.F_LWLAWID
|
||||
order by p2.APPROVEDATE asc
|
||||
) as ts_ref -- مرجع تصویب
|
||||
,(
|
||||
SELECT cbt.CAPTION
|
||||
FROM lwLaw l2
|
||||
left JOIN cmBasetable cbt ON l2.[F_LWBASETABLEID_REGULATIONTYPE] = cbt.ID
|
||||
where l1.ID = l2.id
|
||||
) as regulationType
|
||||
|
||||
FROM [Qavanin].[dbo].[lwLaw] l1
|
||||
left JOIN cmBasetable cbt ON l1.F_LWBASETABLEID_LAWTYPE = cbt.ID
|
||||
left join lwLawSectionStatus lss on lss.id= l1.[F_CMBASETABLEID_LASTSTATUS]
|
||||
|
||||
where ( l1.ISLAW = 1 or l1.ISREGULATION = 1 )
|
||||
'''
|
||||
|
||||
|
||||
|
||||
def isNeedHtml(html):
|
||||
if "<TABLE" in html or "<table" in html or "</TR" in html or "</tr" in html :
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
cursor.execute(query)
|
||||
|
||||
|
||||
url = BASE_URL + "repo/majles/qaqanon/multi/add"
|
||||
|
||||
headers = HEADERS
|
||||
|
||||
bulk_count = 1
|
||||
bulk_data = []
|
||||
|
||||
t1= datetime.datetime.now()
|
||||
print(t1)
|
||||
i = 0
|
||||
while 1:
|
||||
# print(i)
|
||||
i=i+1
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
|
||||
# if i > 1000:
|
||||
# break
|
||||
# print(row.sectionId)
|
||||
|
||||
|
||||
title = normalYehKe( row.title )
|
||||
|
||||
eid='qq'+ str(row.Id)
|
||||
|
||||
main_type = ''
|
||||
if(row.ISLAW == 1):
|
||||
main_type = 'قانون'
|
||||
elif(row.ISREGULATION == 1):
|
||||
main_type = 'مقرره'
|
||||
|
||||
sub_type = ''
|
||||
if(row.ISLAW == 1):
|
||||
sub_type = row.lawType
|
||||
elif(row.ISREGULATION == 1):
|
||||
sub_type = row.regulationType
|
||||
sub_type = normalYehKe(sub_type)
|
||||
|
||||
qanon_number = ''
|
||||
if(row.ISLAW == 1):
|
||||
qanon_number = row.LAWNO
|
||||
elif(row.ISREGULATION == 1):
|
||||
qanon_number = row.RULENO
|
||||
|
||||
# other_type = 'اصلی' اصلاحی....
|
||||
# action_type ...
|
||||
|
||||
|
||||
|
||||
ts_year = ''
|
||||
if row.aproveDate :
|
||||
items = row.aproveDate.split("/")
|
||||
if items.__len__() > 0:
|
||||
ts_year = items[0]
|
||||
|
||||
ts_ref = normalYehKe(row.ts_ref)
|
||||
|
||||
sort_date_timestamp = -15000000000 # 9/2/1494, 12:45:44 AM # خطا یا خالی
|
||||
try:
|
||||
sort_date_timestamp = getSortTimestamp(row.aproveDate)
|
||||
except Exception as e:
|
||||
sort_date_timestamp = -15000000000 # 9/2/1494, 12:45:44 AM # خطا یا خالی
|
||||
|
||||
expire_date = row.expireDate.strip()
|
||||
|
||||
qanon_etebar = ''
|
||||
if row.qanon_etebar :
|
||||
qanon_etebar = row.qanon_etebar
|
||||
|
||||
|
||||
data={
|
||||
'id':eid,
|
||||
'ref_id':row.Id,
|
||||
'main_type': main_type,
|
||||
'sub_type': sub_type,
|
||||
'title': title,
|
||||
'expire_date': expire_date,
|
||||
'ts_date': row.aproveDate,
|
||||
'ts_year': ts_year,
|
||||
'ts_ref': ts_ref,
|
||||
'qanon_etebar' : qanon_etebar,
|
||||
'sort_date_timestamp': sort_date_timestamp, # created from repairQanon.getSortTimestamp
|
||||
}
|
||||
|
||||
if bulk_count > 100:
|
||||
print('=' * 10 )
|
||||
print(str(i)+ ', id=' + eid)
|
||||
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
# print(response)
|
||||
# print(response.text)
|
||||
bulk_data = []
|
||||
bulk_count = 0
|
||||
# print(response.text)
|
||||
#print(row.txt)
|
||||
|
||||
bulk_data.append(data)
|
||||
bulk_count +=1
|
||||
|
||||
|
||||
|
||||
if bulk_count > 0:
|
||||
print(bulk_count)
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
|
||||
cursor.close()
|
||||
cnxn.close()
|
||||
print('end success')
|
||||
t2= datetime.datetime.now()
|
||||
print(t2-t1)
|
||||
@@ -0,0 +1,184 @@
|
||||
import json
|
||||
import requests
|
||||
from config_base import *
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from html import escape
|
||||
import json
|
||||
from decimal import Decimal
|
||||
import datetime
|
||||
|
||||
|
||||
from config_base import *
|
||||
from general_functions import *
|
||||
|
||||
cursor, cnxn = create_cursor()
|
||||
|
||||
# Does quasi the same things as json.loads from here: https://pypi.org/project/dynamodb-json/
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, Decimal):
|
||||
return float(obj)
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
||||
# اجرای کوئری SQL و خواندن دادهها به یک DataFrame
|
||||
query = """
|
||||
SELECT
|
||||
l1.F_LWLAWID_LAW as id
|
||||
, l1.F_LWSECTIONID as section_id
|
||||
--, l2.CAPTION as from_title
|
||||
-- ,(select top(1) tt1.id from lwSection tt1 where tt1.F_LWLAWID=l1.F_LWLAWID_LAW and tt1.FULLPATH = 'عنوان') as section_id2
|
||||
, l3.[FULLPATH] as from_section_title
|
||||
, l1.ISREFERENCE
|
||||
, l1.F_LWLAWID_REGULATION as to_id
|
||||
, l4.CAPTION as to_title
|
||||
, 'مقرره' as to_type
|
||||
|
||||
|
||||
FROM [Qavanin].[dbo].[lwLawRegulation] l1
|
||||
left join lwLaw l2 on l1.F_LWLAWID_LAW=l2.id
|
||||
left join lwsection l3 on l1.F_LWSECTIONID=l3.id
|
||||
left join lwLaw l4 on l1.F_LWLAWID_REGULATION=l4.id
|
||||
|
||||
order by l1.F_lwlawid_law, l1.F_LWLAWID_REGULATION , l1.F_LWSECTIONID
|
||||
|
||||
"""
|
||||
|
||||
cursor.execute(query)
|
||||
|
||||
url = BASE_URL + "repo/majles/qaqanon/multi/update"
|
||||
|
||||
headers = HEADERS
|
||||
|
||||
|
||||
bulk_count = 1
|
||||
bulk_data = []
|
||||
previd = ''
|
||||
ref_state_array = []
|
||||
|
||||
t1= datetime.datetime.now()
|
||||
print("start time: " + str(t1))
|
||||
i = 0
|
||||
all_data = []
|
||||
repeat_data = []
|
||||
|
||||
relations = []
|
||||
prev_eid = ''
|
||||
prev_sectionid = ''
|
||||
prev_to_id = ''
|
||||
|
||||
while 1:
|
||||
|
||||
i += 1
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
|
||||
eid='qq'+ str(row.id)
|
||||
sectionid = str(row.section_id)
|
||||
to_id = str(row.to_id)
|
||||
|
||||
|
||||
# ارتباط با خودش بی معنی است
|
||||
# چند مورد در دیتابیس بود
|
||||
if row.id == row.to_id :
|
||||
continue
|
||||
|
||||
if eid == prev_eid and to_id == prev_to_id :
|
||||
if prev_sectionid == sectionid :
|
||||
continue
|
||||
|
||||
prev_to_id = to_id
|
||||
prev_sectionid = sectionid
|
||||
|
||||
rel_type = 'عادی'
|
||||
if int(row.ISREFERENCE) == 1:
|
||||
rel_type = 'استناد'
|
||||
|
||||
from_type = "کل قانون"
|
||||
if row.section_id :
|
||||
from_type = "جزء قانون"
|
||||
|
||||
from_section_title = ''
|
||||
if row.from_section_title :
|
||||
from_section_title = row.from_section_title
|
||||
|
||||
to_title = normalYehKe( row.to_title )
|
||||
to_type = row.to_type
|
||||
|
||||
|
||||
relation = {
|
||||
"from_type": from_type,
|
||||
"from_section_id" : sectionid,
|
||||
"from_section_title" : from_section_title,
|
||||
"rel_type" : rel_type,
|
||||
"to_type" : to_type,
|
||||
"to_id" : to_id ,
|
||||
"to_title" : to_title,
|
||||
"wait" : 1,
|
||||
"rel_key" : 'qavanin',
|
||||
}
|
||||
|
||||
#print('%'*20, 'eid= ', eid, ' , ... prev_eid= ', prev_eid)
|
||||
#print('--------- relations' , len(relations) )
|
||||
#print(relation )
|
||||
if (i%100) == 0 :
|
||||
print('^' * 10, ' id=', eid, ' i=',i)
|
||||
|
||||
if prev_eid == '':
|
||||
prev_eid = eid
|
||||
continue
|
||||
elif prev_eid == eid :
|
||||
relations.append(relation)
|
||||
continue
|
||||
else :
|
||||
data={
|
||||
'id' : prev_eid,
|
||||
'qanon_relations' : relations
|
||||
}
|
||||
bulk_data.append(data)
|
||||
bulk_count +=1
|
||||
|
||||
prev_eid = eid
|
||||
relations=[]
|
||||
relations.append(relation)
|
||||
|
||||
|
||||
if bulk_count > 10:
|
||||
print('=' * 10 )
|
||||
print(str(i)+ ', id=' + eid)
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
print(response)
|
||||
bulk_data = []
|
||||
bulk_count = 0
|
||||
# print(response.text)
|
||||
#print(row.txt)
|
||||
|
||||
|
||||
|
||||
if len(relations) :
|
||||
data={
|
||||
'id' : prev_eid,
|
||||
'qanon_relations' : relations
|
||||
}
|
||||
bulk_data.append(data)
|
||||
bulk_count +=1
|
||||
|
||||
|
||||
# print(bulk_count)
|
||||
if len(bulk_data) :
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
print(response)
|
||||
# print(response.text )
|
||||
|
||||
cursor.close()
|
||||
cnxn.close()
|
||||
t2= datetime.datetime.now()
|
||||
print("update rows count: " + str(len(all_data)))
|
||||
print("finished time: " + str(t2))
|
||||
print("process time: " + str(t2-t1))
|
||||
print('*********** end success ***********')
|
||||
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
import json
|
||||
import requests
|
||||
from config_base import *
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from html import escape
|
||||
import json
|
||||
from decimal import Decimal
|
||||
import datetime
|
||||
|
||||
|
||||
from config_base import *
|
||||
from general_functions import *
|
||||
|
||||
cursor, cnxn = create_cursor()
|
||||
|
||||
# Does quasi the same things as json.loads from here: https://pypi.org/project/dynamodb-json/
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, Decimal):
|
||||
return float(obj)
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
||||
# اجرای کوئری SQL و خواندن دادهها به یک DataFrame
|
||||
query = """
|
||||
SELECT
|
||||
l1.[F_LWLAWID] as id
|
||||
,[F_LWSECTIONID] as sectionid
|
||||
, ls.[FULLPATH] as from_section_title
|
||||
,[ISRELATED]
|
||||
--,[F_CMBASETABLEID_OPBASEDOCTYPE]
|
||||
--,l4.CAPTION
|
||||
,[F_OPOPINIONID] as to_id
|
||||
,og.CAPTION as to_type
|
||||
,l3.CAPTION as to_title
|
||||
|
||||
FROM [Qavanin].[dbo].[opOpinionLaw] l1
|
||||
left join [opOpinion] l2 on l1.[F_OPOPINIONID] = l2.id
|
||||
left join opOpiniongiver og on l2.F_OPOPINIONGIVERID = og.id
|
||||
left join lwLaw l3 on l2.[F_LWLAWID] = l3.id
|
||||
left join lwsection ls on l1.F_LWSECTIONID=ls.id
|
||||
|
||||
--left join lwLaw l4 on l1.[F_LWLAWID] = l4.id
|
||||
|
||||
order by l1.[F_LWLAWID], [F_OPOPINIONID], [F_LWSECTIONID]
|
||||
|
||||
"""
|
||||
|
||||
cursor.execute(query)
|
||||
|
||||
url = BASE_URL + "repo/majles/qaqanon/multi/update"
|
||||
|
||||
headers = HEADERS
|
||||
|
||||
|
||||
bulk_count = 1
|
||||
bulk_data = []
|
||||
previd = ''
|
||||
ref_state_array = []
|
||||
|
||||
t1= datetime.datetime.now()
|
||||
print("start time: " + str(t1))
|
||||
i = 0
|
||||
all_data = []
|
||||
repeat_data = []
|
||||
|
||||
relations = []
|
||||
prev_eid = ''
|
||||
prev_sectionid = ''
|
||||
prev_to_id = ''
|
||||
|
||||
while 1:
|
||||
|
||||
i += 1
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
|
||||
eid='qq'+ str(row.id)
|
||||
sectionid = str(row.sectionid)
|
||||
to_id = str(row.to_id)
|
||||
|
||||
|
||||
if eid == prev_eid and to_id == prev_to_id :
|
||||
if prev_sectionid == sectionid :
|
||||
continue
|
||||
|
||||
prev_to_id = to_id
|
||||
prev_sectionid = sectionid
|
||||
|
||||
rel_type = 'عادی'
|
||||
if int(row.ISRELATED) == 1:
|
||||
rel_type = 'استناد'
|
||||
|
||||
from_type = "کل قانون"
|
||||
if sectionid :
|
||||
from_type = "جزء قانون"
|
||||
|
||||
from_section_title = ''
|
||||
if row.from_section_title :
|
||||
from_section_title = row.from_section_title
|
||||
|
||||
to_title = normalYehKe( row.to_title )
|
||||
|
||||
to_type = row.to_type.strip()
|
||||
|
||||
if to_type == 'راي هيات عمومي ديوان عدالت اداري' :
|
||||
to_type = 'رای دیوان عدالت اداری'
|
||||
if to_type == 'راي وحدت رويه ديوان عالي كشور' :
|
||||
to_type = 'رای وحدت رویه'
|
||||
if to_type == 'اداره کل حقوقی قوه قضائیه' :
|
||||
to_type = 'نشست قضایی'
|
||||
if to_type == 'نظر رياست مجلس - اصول 85 و 138' :
|
||||
to_type = 'نظر ریاست مجلس'
|
||||
|
||||
relation = {
|
||||
"from_type": from_type,
|
||||
"from_section_id" : sectionid,
|
||||
"from_section_title" : from_section_title,
|
||||
"rel_type" : rel_type,
|
||||
"to_type" : to_type,
|
||||
"to_id" : to_id ,
|
||||
"to_title" : to_title,
|
||||
"wait" : 1,
|
||||
"rel_key" : 'qavanin',
|
||||
}
|
||||
|
||||
#print('%'*20, 'eid= ', eid, ' , ... prev_eid= ', prev_eid)
|
||||
#print('--------- relations' , len(relations) )
|
||||
#print(relation )
|
||||
if (i%100) == 0 :
|
||||
print('^' * 10, ' id=', eid, ' i=',i)
|
||||
|
||||
if prev_eid == '':
|
||||
prev_eid = eid
|
||||
continue
|
||||
elif prev_eid == eid :
|
||||
relations.append(relation)
|
||||
continue
|
||||
else :
|
||||
data={
|
||||
'id' : prev_eid,
|
||||
'opinion_relations' : relations
|
||||
}
|
||||
bulk_data.append(data)
|
||||
bulk_count +=1
|
||||
|
||||
prev_eid = eid
|
||||
relations=[]
|
||||
relations.append(relation)
|
||||
|
||||
|
||||
if bulk_count > 10:
|
||||
print('=' * 10 )
|
||||
print(str(i)+ ', id=' + eid)
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
print(response)
|
||||
bulk_data = []
|
||||
bulk_count = 0
|
||||
# print(response.text)
|
||||
#print(row.txt)
|
||||
|
||||
|
||||
|
||||
if len(relations) :
|
||||
data={
|
||||
'id' : prev_eid,
|
||||
'opinion_relations' : relations
|
||||
}
|
||||
bulk_data.append(data)
|
||||
bulk_count +=1
|
||||
|
||||
|
||||
# print(bulk_count)
|
||||
if len(bulk_data) :
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
print(response)
|
||||
# print(response.text )
|
||||
|
||||
cursor.close()
|
||||
cnxn.close()
|
||||
t2= datetime.datetime.now()
|
||||
print("update rows count: " + str(len(all_data)))
|
||||
print("finished time: " + str(t2))
|
||||
print("process time: " + str(t2-t1))
|
||||
print('*********** end success ***********')
|
||||
|
||||
@@ -0,0 +1,213 @@
|
||||
import json
|
||||
import requests
|
||||
from config_base import *
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from html import escape
|
||||
import json
|
||||
from decimal import Decimal
|
||||
import datetime
|
||||
|
||||
|
||||
from config_base import *
|
||||
from general_functions import *
|
||||
|
||||
# موقت
|
||||
# این برنامه موقتا بخاطر اصلاح داده اجرا شد، اگر از ابتدا انتقال داده انجام شود این بخش خودکار انجام خواهد شد
|
||||
|
||||
cursor, cnxn = create_cursor()
|
||||
|
||||
# Does quasi the same things as json.loads from here: https://pypi.org/project/dynamodb-json/
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, Decimal):
|
||||
return float(obj)
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
||||
query='SELECT ID,CAPTION FROM [Qavanin].[dbo].[cmOrganization]'
|
||||
cursor.execute(query)
|
||||
|
||||
ORG_DICT = {}
|
||||
|
||||
while True:
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
|
||||
|
||||
rr = {"id" : int(row.ID), 'title': row.CAPTION}
|
||||
ORG_DICT[str(int(row.ID))] = {"id" : row.ID, 'title': row.CAPTION}
|
||||
|
||||
#نکته : برای مقررات هیچ موردی نبود که جدولی باشد
|
||||
query = '''
|
||||
|
||||
SELECT
|
||||
F_LWLAWID as F_LWLAWID,
|
||||
p.ID as Phase_ID,
|
||||
isnull(COMMANDDATE,'') as COMMANDDATE ,
|
||||
isnull(COMMANDNO,'') as COMMANDNO,
|
||||
isnull(NEWSPAPERDATE,'') as NEWSPAPERDATE,
|
||||
isnull(NEWSPAPERNO,'') as NEWSPAPERNO,
|
||||
isnull(o.CAPTION,'') as organization_title
|
||||
,(SELECT STRING_AGG(CONVERT(NVARCHAR(max),F_CMORGANIZATIONID), ',') WITHIN GROUP (ORDER BY ID) AS AggregatedResult FROM [lwReceiver] where F_LWLAWID=p.[F_LWLAWID]) as receiver
|
||||
,(SELECT STRING_AGG(CONVERT(NVARCHAR(max),F_CMORGANIZATIONID), ',') WITHIN GROUP (ORDER BY ID) AS AggregatedResult FROM [lwExecutor] where F_LWLAWID=p.[F_LWLAWID]) as exceuter
|
||||
,(SELECT top (1) [EXECUTIONDATE] FROM [lwExecuteCondition] where [F_PHASEID]=p.id) as EXECUTIONDATE
|
||||
FROM [Qavanin].[dbo].[lwPhase] p
|
||||
left join cmOrganization o on p.F_CMORGANIZATIONID = o.ID
|
||||
left join lwLaw l1 on p.F_LWLAWID= l1.ID
|
||||
|
||||
-- order by F_LWLAWID --بعضی موارد تکرار شده اند
|
||||
'''
|
||||
|
||||
cursor.execute(query)
|
||||
|
||||
|
||||
url = BASE_URL + "repo/majles/qaqanon/multi/update"
|
||||
|
||||
headers = HEADERS
|
||||
|
||||
bulk_count = 1
|
||||
bulk_data = []
|
||||
previd = ''
|
||||
ref_state_array = []
|
||||
|
||||
t1= datetime.datetime.now()
|
||||
print("start time: " + str(t1))
|
||||
i = 0
|
||||
all_data = []
|
||||
repeat_data = []
|
||||
while 1:
|
||||
|
||||
i += 1
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
phase_id = str(int(row.Phase_ID.real))
|
||||
law_id = str(int(row.F_LWLAWID.real))
|
||||
eb_number = row.COMMANDNO.strip() if row.COMMANDNO else ''
|
||||
eb_date = row.COMMANDDATE.strip() if row.COMMANDDATE else ''
|
||||
eb_ref = row.organization_title.strip() if row.organization_title else '' # نرمالایز میخواد؟
|
||||
rrk_number = row.NEWSPAPERNO.strip() if row.NEWSPAPERNO else ''
|
||||
rrk_date = row.NEWSPAPERDATE.strip() if row.NEWSPAPERDATE else ''
|
||||
exec_date = row.EXECUTIONDATE.strip() if row.EXECUTIONDATE else ''
|
||||
receiver_ids = row.receiver
|
||||
exceuter_ids = row.exceuter
|
||||
|
||||
if eb_date == '0000/00/00' :
|
||||
eb_date = ''
|
||||
if rrk_date == '0000/00/00' :
|
||||
rrk_date = ''
|
||||
if exec_date == '0000/00/00' :
|
||||
exec_date = ''
|
||||
|
||||
if eb_number == 'نامعلوم' or eb_number == 'ندارد':
|
||||
eb_number = ''
|
||||
if rrk_number == 'نامعلوم' or rrk_number == 'ندارد':
|
||||
rrk_number = ''
|
||||
|
||||
# # جایگذاری مقدار خالی به جای نامعلوم
|
||||
# if eb_number.__contains__("معلوم"):
|
||||
# eb_number = ""
|
||||
# if eb_date.__contains__("معلوم"):
|
||||
# eb_date = ""
|
||||
# if eb_ref.__contains__("معلوم"):
|
||||
# eb_ref = ""
|
||||
# if rrk_number.__contains__("معلوم"):
|
||||
# rrk_number = ""
|
||||
# if rrk_date.__contains__("معلوم"):
|
||||
# rrk_date = ""
|
||||
|
||||
# کمتر از 10 مورد تکرار داشتند، ظاهرا چند بار در روزنامه رسمی منتشر شده و هر بار بخشی از آن ، لذا اولین اطلاعات پر آن برداشته شد
|
||||
if law_id == '178971':
|
||||
eb_number = "7644 ج"
|
||||
if law_id == '244878':
|
||||
eb_number = ""
|
||||
if law_id == '83695':
|
||||
eb_number = "3923"
|
||||
if law_id == '115887':
|
||||
eb_number = ""
|
||||
if law_id == '113211':
|
||||
eb_number = ""
|
||||
if law_id == '83452':
|
||||
eb_number = "70445"
|
||||
if law_id == '111876':
|
||||
eb_number = "7848"
|
||||
if law_id == '198907':
|
||||
eb_number = "36094"
|
||||
if law_id == '87694':
|
||||
eb_number = "36341/ 1"
|
||||
|
||||
if law_id in all_data:
|
||||
repeat_data.append(law_id)
|
||||
continue
|
||||
|
||||
all_data.append(law_id)
|
||||
# print("row: %s" % str(i))
|
||||
|
||||
receiver_organs = []
|
||||
if receiver_ids :
|
||||
for id in receiver_ids.split(',') :
|
||||
if id in ORG_DICT :
|
||||
receiver_organs.append({ "id": id, "title":ORG_DICT[id]["title"]})
|
||||
|
||||
exceuter_organs = []
|
||||
if exceuter_ids :
|
||||
for id in exceuter_ids.split(',') :
|
||||
if id in ORG_DICT :
|
||||
exceuter_organs.append({ "id": id, "title":ORG_DICT[id]["title"]})
|
||||
|
||||
|
||||
|
||||
eid= 'qq' + law_id
|
||||
|
||||
eblagh = {
|
||||
'number' : eb_number,
|
||||
'date' : eb_date,
|
||||
'from' : eb_ref,
|
||||
}
|
||||
|
||||
rrk = {
|
||||
'number' : rrk_number,
|
||||
'date' : rrk_date,
|
||||
}
|
||||
|
||||
data={
|
||||
'id' : eid,
|
||||
'eblagh' : eblagh,
|
||||
'rrk': rrk,
|
||||
'exec_date' : exec_date,
|
||||
'receiver_organs' : receiver_organs,
|
||||
'exceuter_organs' : exceuter_organs,
|
||||
}
|
||||
|
||||
|
||||
if bulk_count > 100:
|
||||
print('=' * 10 )
|
||||
print(str(i)+ ', id=' + eid)
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
print(response)
|
||||
bulk_data = []
|
||||
bulk_count = 0
|
||||
# print(response.text)
|
||||
#print(row.txt)
|
||||
|
||||
bulk_data.append(data)
|
||||
bulk_count +=1
|
||||
|
||||
|
||||
# print(bulk_count)
|
||||
if len(bulk_data) :
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
print(response)
|
||||
# print(response.text )
|
||||
|
||||
cursor.close()
|
||||
cnxn.close()
|
||||
t2= datetime.datetime.now()
|
||||
print("update rows count: " + str(len(all_data)))
|
||||
print("finished time: " + str(t2))
|
||||
print("process time: " + str(t2-t1))
|
||||
print('*********** end success ***********')
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
import json
|
||||
import requests
|
||||
from config_base import *
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from html import escape
|
||||
import json
|
||||
from decimal import Decimal
|
||||
import datetime
|
||||
|
||||
|
||||
from config_base import *
|
||||
from general_functions import *
|
||||
|
||||
# موقت
|
||||
# این برنامه موقتا بخاطر اصلاح داده اجرا شد، اگر از ابتدا انتقال داده انجام شود این بخش خودکار انجام خواهد شد
|
||||
|
||||
cursor, cnxn = create_cursor()
|
||||
|
||||
# Does quasi the same things as json.loads from here: https://pypi.org/project/dynamodb-json/
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, Decimal):
|
||||
return float(obj)
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
||||
#نکته : برای مقررات هیچ موردی نبود که جدولی باشد
|
||||
query = '''SELECT * FROM [Qavanin].[dbo].[lwLaw]
|
||||
where ISLAW=1
|
||||
'''
|
||||
|
||||
cursor.execute(query)
|
||||
|
||||
|
||||
url = BASE_URL + "repo/majles/qaqanon/multi/update"
|
||||
|
||||
headers = HEADERS
|
||||
|
||||
bulk_count = 1
|
||||
bulk_data = []
|
||||
previd = ''
|
||||
ref_state_array = []
|
||||
|
||||
t1= datetime.datetime.now()
|
||||
print("start time: " + str(t1))
|
||||
i = 0
|
||||
all_data = []
|
||||
repeat_data = []
|
||||
while 1:
|
||||
|
||||
i += 1
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
law_id = row.ID
|
||||
caption = str(row.CAPTION)
|
||||
|
||||
eid= 'qq' + str(law_id)
|
||||
|
||||
title_type = getTitleType(caption)
|
||||
|
||||
data={
|
||||
'id' : eid,
|
||||
'title_type': title_type
|
||||
}
|
||||
|
||||
|
||||
if bulk_count > 100:
|
||||
print('=' * 10 )
|
||||
print(str(i)+ ', id=' + eid)
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
print(response)
|
||||
bulk_data = []
|
||||
bulk_count = 0
|
||||
# print(response.text)
|
||||
#print(row.txt)
|
||||
|
||||
bulk_data.append(data)
|
||||
bulk_count +=1
|
||||
|
||||
|
||||
# print(bulk_count)
|
||||
if len(bulk_data) :
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
print(response)
|
||||
# print(response.text )
|
||||
|
||||
cursor.close()
|
||||
cnxn.close()
|
||||
t2= datetime.datetime.now()
|
||||
print("update rows count: " + str(len(all_data)))
|
||||
print("finished time: " + str(t2))
|
||||
print("process time: " + str(t2-t1))
|
||||
print('*********** end success ***********')
|
||||
|
||||
@@ -0,0 +1,324 @@
|
||||
import json
|
||||
import requests
|
||||
from config_base import *
|
||||
import pyodbc
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from html import escape
|
||||
import json
|
||||
from decimal import Decimal
|
||||
import datetime
|
||||
import time
|
||||
import sys
|
||||
import traceback
|
||||
import re
|
||||
|
||||
from config_base import *
|
||||
from general_functions import *
|
||||
|
||||
|
||||
cursor, cnxn = create_cursor()
|
||||
|
||||
#Does quasi the same things as json.loads from here: https://pypi.org/project/dynamodb-json/
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, Decimal):
|
||||
return float(obj)
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
||||
|
||||
query = '''
|
||||
select
|
||||
s.ID as sectionId
|
||||
,isnull(s.CAPTION,'') as title -- عنوان بخش: مثلا ماده 5
|
||||
,isnull(s.F_PARENTID,0) as parentId
|
||||
,isnull(lss.CAPTION,'') as sectionStatus -- lwLawSectionStatus_table: ... منسوخه، معتبر، اصلاحی، موقت و
|
||||
,isnull(lss2.CAPTION,'') as qanon_etebar -- برای کل قانون نه جزء یا ماده خاص : ... منسوخه، معتبر، اصلاحی، موقت و
|
||||
,isnull(s.SECTIONTEXT,'') as sectionText -- متن ماده یا تبصره
|
||||
,isnull(s.SECTIONLEVEL,0) as sectionLevel -- نسبت به عنوان قانون نامرتب و دارای مقدار تکراری هم هست ؟؟؟
|
||||
,isnull(nestedLawType.CAPTION,'') as lawType
|
||||
--,isnull(nestedLawStatus.CAPTION,'') as lawStatus
|
||||
,isnull(s.TEXTORDER,0) as textOrder -- ترتیب نمایش مواد و تبصره ها
|
||||
,s.STATENO as stateNo -- ???
|
||||
,isnull(s.SECTIONTYPENO,0) as sectionTypeNumber -- دوهزار رکورد با مقدار صفر دارد اما مقادیر دیگری نیز پذیرفته است ؟؟؟
|
||||
-- بیش از پنج هزار رکورد با مقدار بالاتر از 1500 دارد که چنین مقادیری در جدول سکشن_تایپ وجود ندارد پس با این جدول رابطه ندارد
|
||||
,isnull(l.CAPTION,'') as lawTitle -- عنوان قانون
|
||||
,isnull(l.ID,0) as lawId -- شناسه قانون
|
||||
,isnull(l.APPROVEDATE,'') as aproveDate -- تاریخ تصویب
|
||||
,isnull(l.EXPIREDATE,'') as expireDate -- تاریخ انقضا
|
||||
--,isnull(s.F_LWPHASEID,0) as phaseId -- شناسه فاز
|
||||
,s.FULLPATH as sectionFullPath -- عنوان ماده یا تبصره
|
||||
,isnull(s.SECTIONTYPENOTEXT,'') as sectionType -- ??? استفساریه، کنوانسیون، موافقت نامه، اساسنامه، تفسیر، دوم ، سوم ، چهارم، دوازدهم، خالی، 1، 2، 3، 4
|
||||
,isnull(s.FIRSTSATENO,0) as firstStateNo -- ??? بازه 0 تا 169
|
||||
,isnull(s.LASTSTATENO,0) as lastStateNo -- ??? بازه 0 تا 112
|
||||
,isnull(s.HIERARCHY,'') as hierarchy
|
||||
,isnull(s.DISPLAYINCONTENTS,0) as displayInContents -- ??? صد و پنجاه و سه رکورد دارای مقدار یک و بقیه یک میلیون رکورد مقدار 0 دارد
|
||||
,isnull(s.ISINTERPRETATION,0) as isInterpretation -- ??? چهارصد و پنجاه و سه رکورد با مقدار یک دارد و بقیه مقادیر نال است
|
||||
,(SELECT STRING_AGG(CONVERT(NVARCHAR(max),F_TOPICID), ',') WITHIN GROUP (ORDER BY ID) AS AggregatedResult FROM lwsectiontopic where [F_SECTIONID]=s.id) as topics
|
||||
,l.[ISLAW] -- قانون
|
||||
,l.[ISREGULATION] -- مقرره
|
||||
,l.[ISCORRECTIONLETTER] -- اصلاحیه
|
||||
,(
|
||||
SELECT top (1) p3.CAPTION
|
||||
FROM [lwPhase] p1
|
||||
left join [lwApprover] p2 on p1.ID=p2.F_LWPHASEID
|
||||
left join cmOrganization p3 on p2.F_CMORGANIZATIONID = p3.id
|
||||
where l.ID = p1.F_LWLAWID
|
||||
order by p2.APPROVEDATE asc
|
||||
) as ts_ref -- مرجع تصویب
|
||||
,(
|
||||
SELECT cbt.CAPTION
|
||||
FROM lwLaw l2
|
||||
left JOIN cmBasetable cbt ON l2.[F_LWBASETABLEID_REGULATIONTYPE] = cbt.ID
|
||||
where l.ID = l2.id
|
||||
) as regulationType
|
||||
|
||||
|
||||
from lwSection s
|
||||
left join lwLawSectionStatus lss on s.F_CMBASETABLEID_SECTIONSTATUS = lss.ID
|
||||
left join lwLaw l on s.F_LWLAWID = l.ID
|
||||
left join lwLawSectionStatus lss2 on lss2.id= l.[F_CMBASETABLEID_LASTSTATUS]
|
||||
left JOIN (
|
||||
SELECT l2.F_LWBASETABLEID_LAWTYPE,l2.ID,cbt.CAPTION
|
||||
FROM lwLaw l2
|
||||
left JOIN cmBasetable cbt ON l2.F_LWBASETABLEID_LAWTYPE = cbt.ID
|
||||
) AS nestedLawType ON s.F_LWLAWID = nestedLawType.ID
|
||||
left JOIN (
|
||||
SELECT l2.[F_LWBASETABLEID_REGULATIONTYPE],l2.ID,cbt.CAPTION
|
||||
FROM lwLaw l2
|
||||
left JOIN cmBasetable cbt ON l2.[F_LWBASETABLEID_REGULATIONTYPE] = cbt.ID
|
||||
) AS nestedRegulationType ON s.F_LWLAWID = nestedRegulationType.ID
|
||||
|
||||
where l.ISLAW = 1
|
||||
order by s.F_LWLAWID,textOrder
|
||||
'''
|
||||
|
||||
#####
|
||||
# --,nestedSectionChanghed.APPROVEDATE as effect_Date,
|
||||
# --nestedSectionChanghed.textEFFECTIVE as effect_text,
|
||||
# --nestedSectionChanghed.textPrev as effect_prev_text,
|
||||
# --nestedSectionChanghed.qanonEFFECTIVE as effect_qanon,
|
||||
# --nestedSectionChanghed.F_LWLAWID_EFFECTIVE as effect_section_id,
|
||||
# --nestedSectionChanghed.[F_LWSECTIONID_EFFECTIVE] as effect_qanon_id
|
||||
#####
|
||||
# left join (
|
||||
# SELECT
|
||||
# gl3.[SECTIONTEXT] as textEFFECTIVE,
|
||||
# gl5.SECTIONTEXT as textPrev,
|
||||
# gl4.APPROVEDATE,
|
||||
# gl4.CAPTION as qanonEFFECTIVE,
|
||||
# gl1.F_LWLAWID_EFFECTIVE,
|
||||
# gl1.[F_LWSECTIONID_EFFECTIVE],
|
||||
# gl1.[F_LWSECTIONID_EFFECTED]
|
||||
# FROM [Qavanin].[dbo].[lwSectionChange] gl1
|
||||
# left join lwSection gl2 on gl2.ID=gl1.[F_LWSECTIONID_EFFECTED]
|
||||
# left join lwSection gl3 on gl3.ID=gl1.[F_LWSECTIONID_EFFECTIVE]
|
||||
# left join lwLaw gl4 on gl1.F_LWLAWID_EFFECTIVE=gl4.ID
|
||||
# left join lwSectionLog gl5 on gl1.[F_LWSECTIONLOGID_EFFECTED]=gl5.ID
|
||||
# where
|
||||
# gl4.ISLAW = 1
|
||||
# and gl1.[F_LWSECTIONID_EFFECTED] is not null
|
||||
# ) as nestedSectionChanghed ON s.id=nestedSectionChanghed.[F_LWSECTIONID_EFFECTED]
|
||||
|
||||
|
||||
def isNeedHtml(html):
|
||||
if "<TABLE" in html or "<table" in html or "</TR" in html or "</tr" in html :
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
cursor.execute(query)
|
||||
|
||||
|
||||
url = BASE_URL + "repo/majles/section/multi/add"
|
||||
dict_topic = json.loads(open("list_LWTopic.json").read())
|
||||
|
||||
headers = HEADERS
|
||||
|
||||
bulk_count = 1
|
||||
bulk_data = []
|
||||
|
||||
t1= datetime.datetime.now()
|
||||
print(t1)
|
||||
i = 1
|
||||
while 1:
|
||||
# print(i)
|
||||
i=i+1
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
|
||||
# if i > 1000:
|
||||
# break
|
||||
# print(row.sectionId)
|
||||
|
||||
html = ''
|
||||
if isNeedHtml(row.sectionText) :
|
||||
html = row.sectionText
|
||||
|
||||
try:
|
||||
soup = BeautifulSoup(row.sectionText, "html.parser")
|
||||
text = soup.get_text("\n", strip=True)
|
||||
# text = removeHtmlNoTableTag(row.sectionText) # خطا داره
|
||||
except Exception as e:
|
||||
text = row.sectionText
|
||||
|
||||
text = normalYehKe(text)
|
||||
content_len = text.__len__()
|
||||
|
||||
qanon_title = normalYehKe( row.lawTitle )
|
||||
|
||||
eid='qs'+ str(row.sectionId)
|
||||
|
||||
parentId = '0'
|
||||
if row.parentId != 0 :
|
||||
parentId = 'qs'+ str(row.parentId)
|
||||
lawId='qq'+ str(row.lawId)
|
||||
|
||||
main_type = ''
|
||||
if(row.ISLAW == 1):
|
||||
main_type = 'قانون'
|
||||
elif(row.ISREGULATION == 1):
|
||||
main_type = 'مقرره'
|
||||
|
||||
sub_type = ''
|
||||
if(row.ISLAW == 1):
|
||||
sub_type = row.lawType
|
||||
elif(row.ISREGULATION == 1):
|
||||
sub_type = row.regulationType
|
||||
sub_type = normalYehKe(sub_type)
|
||||
|
||||
# other_type = 'اصلی'
|
||||
# if(row.ISCORRECTIONLETTER == 1):
|
||||
# other_type = 'اصلاحی'
|
||||
|
||||
|
||||
ts_year = ''
|
||||
if row.aproveDate :
|
||||
items = row.aproveDate.split("/")
|
||||
if items.__len__() > 0:
|
||||
ts_year = items[0]
|
||||
|
||||
|
||||
tt = time.time()
|
||||
tt = int( round(tt) * 1000)
|
||||
version_ifo = {
|
||||
"timestamp": tt,
|
||||
"operation": "create",
|
||||
"number" : 1
|
||||
}
|
||||
|
||||
other_info = {
|
||||
"level": row.sectionLevel,
|
||||
"full_path": normalYehKe( row.sectionFullPath ),
|
||||
"number_text":row.sectionType ,
|
||||
"hierarchy" : row.hierarchy
|
||||
}
|
||||
|
||||
topics = []
|
||||
if row.topics:
|
||||
topic_ids = row.topics.split(",")
|
||||
topic_list = list(set(topic_ids))
|
||||
for item in topic_ids:
|
||||
if str(item) in dict_topic:
|
||||
topics.append(
|
||||
{'id': dict_topic[str(item)]['id'], 'title': normalYehKe(dict_topic[str(item)]['title'])}
|
||||
)
|
||||
|
||||
ts_ref = normalYehKe(row.ts_ref)
|
||||
|
||||
if ts_ref == 'مقام معظم رهبری ( فرماندهی کل قوا )' :
|
||||
ts_ref = 'مقام معظم رهبری'
|
||||
|
||||
sort_date_timestamp = -15000000000 # 9/2/1494, 12:45:44 AM # خطا یا خالی
|
||||
try:
|
||||
sort_date_timestamp = getSortTimestamp(row.aproveDate)
|
||||
except Exception as e:
|
||||
sort_date_timestamp = -15000000000 # 9/2/1494, 12:45:44 AM # خطا یا خالی
|
||||
|
||||
expire_date = row.expireDate.strip()
|
||||
|
||||
# state_etebar = normalYehKe(row.lawStatus)
|
||||
state_etebar = normalYehKe(row.sectionStatus)
|
||||
|
||||
qanon_etebar = ''
|
||||
if row.qanon_etebar :
|
||||
qanon_etebar = row.qanon_etebar
|
||||
|
||||
|
||||
|
||||
# ref_state = {}
|
||||
# if row.effect_qanon_id :
|
||||
# efect_section_id='qs'+ str(row.effect_section_id)
|
||||
# efect_qanon_id= 'qq'+ str(row.effect_qanon_id)
|
||||
# ref_state = {
|
||||
# "qanon_id": efect_qanon_id,
|
||||
# "qanon_date": row.effect_Date,
|
||||
# "section_id": efect_section_id,
|
||||
# "qanon_title" : normalYehKe(row.effect_qanon),
|
||||
# # "section_text" : normalYehKe(row.effect_text), # نیاز نیست
|
||||
# "prev_text" : normalYehKe(row.effect_prev_text)
|
||||
# }
|
||||
|
||||
data={
|
||||
'id':eid,
|
||||
'ref_id':row.sectionId,
|
||||
'ref_key':'m_qavanin',
|
||||
'main_type': main_type,
|
||||
'sub_type': sub_type,
|
||||
'content': text,
|
||||
'html' : html,
|
||||
'version_info': version_ifo,
|
||||
'qanon_title': qanon_title,
|
||||
'expire_date': expire_date,
|
||||
'ts_date': row.aproveDate,
|
||||
'ts_year': ts_year,
|
||||
'ts_ref': ts_ref,
|
||||
'state_etebar': state_etebar,
|
||||
'qanon_id': lawId,
|
||||
'parent_id': parentId,
|
||||
'child_order': row.textOrder,
|
||||
'other_info': other_info,
|
||||
'content_len': content_len,
|
||||
'topics': topics,
|
||||
'qanon_etebar' : qanon_etebar,
|
||||
# 'ref_state' : ref_state,
|
||||
#'categories': row.oooo,
|
||||
#'tags': row.oooo,
|
||||
#'keywords': row.oooo,
|
||||
'sort_date_timestamp': sort_date_timestamp, # created from repairQanon.getSortTimestamp
|
||||
}
|
||||
|
||||
if bulk_count > 100:
|
||||
print('=' * 10 )
|
||||
print(str(i)+ ', id=' + eid)
|
||||
print(', lawid=' + lawId)
|
||||
if bulk_count > 0:
|
||||
print(', lawid_first=' + bulk_data[0]['qanon_id'])
|
||||
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
# print(response)
|
||||
bulk_data = []
|
||||
bulk_count = 0
|
||||
# print(response.text)
|
||||
#print(row.txt)
|
||||
|
||||
bulk_data.append(data)
|
||||
bulk_count +=1
|
||||
|
||||
|
||||
|
||||
if bulk_count > 0:
|
||||
print(bulk_count)
|
||||
if bulk_count > 0:
|
||||
print(', lawid_first=' + bulk_data[0]['qanon_id'])
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
|
||||
cursor.close()
|
||||
cnxn.close()
|
||||
print('end success')
|
||||
t2= datetime.datetime.now()
|
||||
print(t2-t1)
|
||||
@@ -0,0 +1,328 @@
|
||||
import json
|
||||
import requests
|
||||
from config_base import *
|
||||
import pyodbc
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from html import escape
|
||||
import json
|
||||
from decimal import Decimal
|
||||
import re
|
||||
import datetime
|
||||
|
||||
from config_base import *
|
||||
from general_functions import *
|
||||
|
||||
'''
|
||||
# این متد یک متن و ایندکس آغاز و پایان یک عبارت درون آن متن را دریافت می کند
|
||||
# و شماره توکن آغازین و توکن پایانی مربوط به عبارت در متن را بر می گرداند
|
||||
def token_state_finder(normalized_section_content, start_index, end_index):
|
||||
before_substring = normalized_section_content[0:start_index].strip()
|
||||
pattern_substring = normalized_section_content[start_index:end_index].strip()
|
||||
before_substring_token_list = before_substring.strip().split()
|
||||
pattern_token_list = pattern_substring.strip().split()
|
||||
start_token_state = len(before_substring_token_list) + 1
|
||||
end_token_state = len(before_substring_token_list) + (len(pattern_token_list))
|
||||
pattern_tokens_state = [
|
||||
{"start_token_state": start_token_state, "end_token_state": end_token_state}
|
||||
]
|
||||
return pattern_tokens_state
|
||||
|
||||
def find_number_indexes_in_string(normalized_string,recognized_numbers):
|
||||
complete_recognized_numbers = []
|
||||
for item in recognized_numbers:
|
||||
number_start_index, number_end_index = find_token_indexes_in_string(normalized_string,item['start_token_index'],item['end_token_index'])
|
||||
complete_recognized_numbers.append(
|
||||
{
|
||||
'number_value' : item['number_value'],
|
||||
'number_token_list' : item['number_token_list'],
|
||||
'start_token_index' : item['start_token_index'],
|
||||
'end_token_index' : item['end_token_index'],
|
||||
"start_number_state": number_start_index,
|
||||
"end_number_state" : number_end_index
|
||||
}
|
||||
)
|
||||
return complete_recognized_numbers
|
||||
|
||||
# این متد متن اصلی یک متن، توکن آغازین و توکن پایانی مربوط به یک عبارت را می گیرد
|
||||
# و ایندکس آغاز و ایندکس پایان متن وارد شده را بر می گرداند
|
||||
def find_token_indexes_in_string(normalized_string,start_token_index,end_token_index):
|
||||
before_tokens = normalized_string.split()[0:start_token_index]
|
||||
content_tokens = normalized_string.split()[start_token_index:end_token_index + 1]
|
||||
content_start_index = 0
|
||||
content_end_index = 0
|
||||
# شمردن تعداد کاراکترهای هر توکن در لیست توکن قبل از عدد
|
||||
for token in before_tokens:
|
||||
content_start_index += len(token)
|
||||
# اضافه کردن تعداد فاصله های خالی یا همان اسپیس به عدد ایندکس شروع عدد
|
||||
content_start_index += len(before_tokens) + 1
|
||||
|
||||
# شمردن تعداد کاراکترهای هر توکن در لیست توکن مربوط به عدد
|
||||
for token in content_tokens:
|
||||
content_end_index += len(token)
|
||||
# اضافه کردن تعداد فاصله های خالی یا همان اسپیس به عدد ایندکس پایان عدد
|
||||
content_end_index += (content_start_index - 1) + (len(content_tokens) - 1)
|
||||
|
||||
return content_start_index, content_end_index
|
||||
|
||||
# این متد، متنی را دریافت می کند و الگوهای تعریف شده را در آن جستجو می کند و آرایه ای از عبارات مطابق با هر الگو،
|
||||
# شماره ایندکس شروع و پایان هر عبارت، عنوان و محتوای الگو، و شماره توکن شروع و توکن پایانی هر عبارت
|
||||
# پیدا شده را بر می گرداند
|
||||
def regex_patterns_finder(sectoin_content):
|
||||
regex_patterns = [
|
||||
{
|
||||
"asle N asasi": r"اصل\s*شماره\s*(\d+)\s*قانون\s*اساسی\s*جمهوری\s*اسلامی\s*ایران"
|
||||
}, # اصل شماره فلان قانون اساسی جمهوری اسلامی ایران
|
||||
{
|
||||
"qanone asasi": r"(?<!^)\b\sقانون\sاساسی\sجمهوری\sاسلامی\sایران"
|
||||
}, # قانون اساسی جمهوری اسلامی ایران که در اول پاراگراف نباشد
|
||||
{"in qanon": r"\sاین\sقانون"}, # این قانون
|
||||
{"qanone foq": r"\sقانون\sفوق"}, # قانون فوق
|
||||
{"eslahe qanon": r"\sقانون\sاصلاح"}, # اصلاح قانون
|
||||
{"tabsare foq": r"\sتبصره\sفوق"}, # تبصره فوق
|
||||
{"made foq": r"\ماده\sفوق"}, # ماده فوق
|
||||
{"made vahed": r"\sماده\sواحده"}, # ماده واحده
|
||||
{
|
||||
"tabsare N": r"^\bتبصره\s*شماره\s*(\d+)\s*"
|
||||
}, # تبصره شماره فلان که فقط اول پاراگراف باشد
|
||||
{
|
||||
"f tabsare N": r"(?<!^)\bتبصره\sشماره\s(\d+)\s"
|
||||
}, # تبصره شماره فلان که همه جا غیر از اول پاراگراف باشد
|
||||
{
|
||||
"tabsare N": r"(?<!^)\bتبصره\s(\d+)\s"
|
||||
}, # تبصره شماره فلان که همه جا غیر از اول پاراگراف باشد
|
||||
{
|
||||
"made N": r"ماده ?\(? ?\d+? ?\)?[ :.]"
|
||||
}, # *** ماده فلان که هرجای پاراگراف غیر از اول آن باشد
|
||||
{
|
||||
"f made N": r"^\bماده\s*[(]?\s*(\d+)\s*[)]?\s*"
|
||||
}, # ماده فلان که فقط اول پاراگراف باشد با یا بدون ترکیب عدد با پرانتز
|
||||
]
|
||||
|
||||
matched_array = []
|
||||
for pattern in enumerate(regex_patterns):
|
||||
current_pattern = pattern[1]
|
||||
keys = current_pattern.keys()
|
||||
values = current_pattern.values()
|
||||
value = []
|
||||
key = []
|
||||
for k_items in keys:
|
||||
key.append(k_items)
|
||||
for v_items in values:
|
||||
value.append(v_items)
|
||||
current_pattern_key = key[0]
|
||||
current_pattern_value = value[0]
|
||||
regex = re.compile(current_pattern_value)
|
||||
matches = regex.finditer(sectoin_content)
|
||||
|
||||
for match in matches:
|
||||
# انجام عملیات مرتبط با هر الگو در اینجا
|
||||
founded_item = match.group()
|
||||
start_index = match.start()
|
||||
end_index = match.end() - 1
|
||||
pattern_tokens_state = token_state_finder(
|
||||
sectoin_content, start_index, end_index
|
||||
)
|
||||
matched_array.append(
|
||||
{
|
||||
"founded_item": founded_item,
|
||||
"start_index": start_index,
|
||||
"end_index": end_index,
|
||||
"pattern_key": current_pattern_key,
|
||||
"pattern_value": current_pattern_value,
|
||||
"start_token_state": pattern_tokens_state[0]["start_token_state"],
|
||||
"end_token_state": pattern_tokens_state[0]["end_token_state"],
|
||||
}
|
||||
)
|
||||
# convertedText = regex.sub(' wwwwwwwww ',convertedText)
|
||||
return matched_array
|
||||
'''
|
||||
|
||||
section_content = """
|
||||
مبلغ آن شش هزار و سيصد و سي و دو ميليون و پانصد هزار (- /۶۳۳۲۵۰۰۰۰۰) ين
|
||||
مبلغ هفت ميليون و نهصد و ده هزار (000 / 910 / 7) ريال جهت
|
||||
مبلغ شانزده ميليون و ششصد و بيست و نه هزار و ششصد و پنجاه و هفت (657 / 629 / 16) ريال
|
||||
قانون اجازه بر اساس ماده (4) قانون مالیات ، پرداخت دودوازدهم هزینه کل کشور بابت دوماهه تیر و مرداد 1323 مصوب 27 تیر ماه 1323 ماده واحده - قانون مصوب 31 فروردین ماه 1323 برای پرداخت هزینههای کشور دردوماهه تیر و مرداد 1323 به قوت خود باقی و به وزارتدارایی اجازه داده میشود هزینه ماههای مذکور را بر طبق قانون مصوب 31 فروردین ماه 1323 بپردازد. تبصره دو - دولت مکلف است بودجههای جزء وزارتخانهها و ادارات را که تاکنون به مجلستسلیم نشده تا 15 مرداد و بودجههای بازرگانی و کارخانجات ومؤسسات اقتصادی راحداکثر تا 15 شهریور به مجلس شورای ملی تقدیم دارد.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cursor, cnxn = create_cursor()
|
||||
|
||||
|
||||
# Does quasi the same things as json.loads from here: https://pypi.org/project/dynamodb-json/
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, Decimal):
|
||||
return float(obj)
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
||||
|
||||
query = """
|
||||
SELECT
|
||||
isnull(o.[ID],0) as ref_id
|
||||
,isnull(l.CAPTION,'') as title
|
||||
,isnull([SUBJECT],'') as title_popular
|
||||
,isnull([OPINIONDATE],'') as ts_date
|
||||
,isnull(op_r.CAPTION,'') as sub_type
|
||||
,isnull(op_r.[F_CMBASETABLEID_OPINIONGROUP],0) as mainType -- 1419 : رای 1418:نظر
|
||||
--,isnull(F_OPOPINIONGIVERID,0) as ts_ref -- ts_ref
|
||||
--,isnull(bt.CAPTION,'') as classification -- عادی، ندارد مهم نیست
|
||||
,isnull(o.[F_LWLAWID],0) as qanon_id
|
||||
,isnull([DISTRIBUTENO],'') as eblagh_number -- ???????? شماره ابلاغ؟
|
||||
,isnull([DISTRIBUTEDATE],'') as eblagh_date -- ???????? تاریخ ابلاغ
|
||||
,isnull(d.DOCTEXT,'') as content -- !!!!!!!!!!!!!!!!!!!!!! داده های این فیلد حجم زیادی دارد
|
||||
,(SELECT STRING_AGG(CONVERT(NVARCHAR(max),[F_LWTOPICID]), ',') WITHIN GROUP (ORDER BY ID) AS AggregatedResult FROM opOpinionTopic where [F_OPOPINIONID]=o.id) as topics
|
||||
FROM [Qavanin].[dbo].[opOpinion] o
|
||||
left join opOpiniongiver op_r on o.F_OPOPINIONGIVERID = op_r.id
|
||||
left join [cmBasetable] bt on o.F_CMBASETABLEID_CLASSIFICATION = bt.ID
|
||||
left join lwLaw l on o.F_LWLAWID = l.ID
|
||||
left join prDoc d on o.F_PRDOCID = d.ID
|
||||
|
||||
"""
|
||||
|
||||
|
||||
cursor.execute(query)
|
||||
|
||||
|
||||
url = BASE_URL + "repo/majles/opinion/multi/add" # POST /repo/majles/opinion/multi/add
|
||||
dict_topic = json.loads(open("list_LWTopic.json").read())
|
||||
|
||||
headers = HEADERS
|
||||
|
||||
bulk_count = 1
|
||||
bulk_data = []
|
||||
|
||||
t1 = datetime.datetime.now()
|
||||
print(t1)
|
||||
i = 1
|
||||
while 1:
|
||||
# print(i)
|
||||
i = i + 1
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
|
||||
# if i > 1000:
|
||||
# break
|
||||
# print(row.sectionId)
|
||||
|
||||
try:
|
||||
soup = BeautifulSoup(row.content, "html.parser")
|
||||
text = soup.get_text("\n", strip=True)
|
||||
except Exception as e:
|
||||
text = row.content
|
||||
text = normalYehKe(text)
|
||||
content_len = text.__len__()
|
||||
|
||||
title = normalYehKe(row.title)
|
||||
|
||||
eid = "qo" + str(row.ref_id)
|
||||
|
||||
qanon_id = "qq" + str(row.qanon_id)
|
||||
|
||||
main_type = ""
|
||||
if row.mainType == 1418:
|
||||
main_type = "نظر"
|
||||
elif row.mainType == 1419:
|
||||
main_type = "رای"
|
||||
|
||||
ts_year = ""
|
||||
if row.ts_date:
|
||||
items = row.ts_date.split("/")
|
||||
if items.__len__() > 0:
|
||||
ts_year = items[0]
|
||||
|
||||
version_ifo = {
|
||||
"timestamp": datetime.datetime.now().timestamp(),
|
||||
"operation": "create",
|
||||
"number": 1,
|
||||
}
|
||||
|
||||
topics = []
|
||||
if row.topics:
|
||||
topic_ids = row.topics.split(",")
|
||||
topic_list = list(set(topic_ids))
|
||||
for item in topic_ids:
|
||||
if str(item) in dict_topic:
|
||||
topics.append(
|
||||
{
|
||||
"id": dict_topic[str(item)]["id"],
|
||||
"title": normalYehKe(dict_topic[str(item)]["title"]),
|
||||
}
|
||||
)
|
||||
|
||||
ts_ref = normalYehKe(row.sub_type)
|
||||
ts_ref = ts_ref.replace("رای وحدت رویه", "")
|
||||
ts_ref = ts_ref.replace("رای", "")
|
||||
ts_ref = ts_ref.replace("نظر", "")
|
||||
ts_ref = ts_ref.replace("- اصول 85 و 138", "")
|
||||
ts_ref = ts_ref.strip()
|
||||
|
||||
sort_date_timestamp = -15000000000 # 9/2/1494, 12:45:44 AM # خطا یا خالی
|
||||
try:
|
||||
sort_date_timestamp = getSortTimestamp(row.ts_date)
|
||||
except Exception as e:
|
||||
sort_date_timestamp = -15000000000 # 9/2/1494, 12:45:44 AM # خطا یا خالی
|
||||
|
||||
sub_type = normalYehKe(row.sub_type)
|
||||
title_popular = normalYehKe(row.title_popular)
|
||||
eblagh_number = normalYehKe(row.eblagh_number)
|
||||
eblagh_date = normalYehKe(row.eblagh_date)
|
||||
|
||||
print(len(text.split()))
|
||||
normalized_section_content, recognized_dates, recognized_numbers = normalizerDate2(text.strip())
|
||||
print(len(normalized_section_content.split()))
|
||||
recognized_numbers = find_number_indexes_in_string(normalized_section_content,recognized_numbers)
|
||||
normalized_section_content = normalized_section_content.strip()
|
||||
founded_patterns_array = regex_patterns_finder(normalized_section_content)
|
||||
|
||||
data = {
|
||||
"id": eid,
|
||||
"title": title,
|
||||
"ref_id": row.ref_id,
|
||||
"ref_key": "m_qavanin",
|
||||
"main_type": main_type,
|
||||
"sub_type": sub_type,
|
||||
"html": row.content,
|
||||
"content": text,
|
||||
"version_info": version_ifo,
|
||||
"ts_date": row.ts_date,
|
||||
"ts_year": ts_year,
|
||||
"ts_ref": ts_ref,
|
||||
"qanon_id": qanon_id,
|
||||
"eblagh_number": eblagh_number,
|
||||
"eblagh_date": eblagh_date,
|
||||
"content_len": content_len,
|
||||
"title_popular": title_popular,
|
||||
"sort_date_timestamp": sort_date_timestamp,
|
||||
}
|
||||
|
||||
if bulk_count > 10:
|
||||
# print('=' * 10 )
|
||||
print(str(i) + ", id=" + eid)
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
print(response)
|
||||
bulk_data = []
|
||||
bulk_count = 1
|
||||
# print(response.text)
|
||||
# print(row.txt)
|
||||
|
||||
bulk_data.append(data)
|
||||
bulk_count += 1
|
||||
|
||||
|
||||
if bulk_count > 0:
|
||||
print(bulk_count)
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
|
||||
cursor.close()
|
||||
cnxn.close()
|
||||
print("end success")
|
||||
t2 = datetime.datetime.now()
|
||||
print(t2 - t1)
|
||||
@@ -0,0 +1,276 @@
|
||||
import json
|
||||
import requests
|
||||
from config_base import *
|
||||
import pyodbc
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from html import escape
|
||||
import json
|
||||
from decimal import Decimal
|
||||
import datetime
|
||||
import time
|
||||
import sys
|
||||
import traceback
|
||||
import re
|
||||
|
||||
from config_base import *
|
||||
from general_functions import *
|
||||
|
||||
|
||||
cursor, cnxn = create_cursor()
|
||||
|
||||
#Does quasi the same things as json.loads from here: https://pypi.org/project/dynamodb-json/
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, Decimal):
|
||||
return float(obj)
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
||||
|
||||
query = '''
|
||||
select
|
||||
s.ID as sectionId
|
||||
,isnull(s.CAPTION,'') as title -- عنوان بخش: مثلا ماده 5
|
||||
,isnull(s.F_PARENTID,0) as parentId
|
||||
,isnull(lss.CAPTION,'') as sectionStatus -- lwLawSectionStatus_table: ... منسوخه، معتبر، اصلاحی، موقت و
|
||||
,isnull(lss2.CAPTION,'') as qanon_etebar -- برای کل قانون نه جزء یا ماده خاص : ... منسوخه، معتبر، اصلاحی، موقت و
|
||||
,isnull(s.SECTIONTEXT,'') as sectionText -- متن ماده یا تبصره
|
||||
,isnull(s.SECTIONLEVEL,0) as sectionLevel -- نسبت به عنوان قانون نامرتب و دارای مقدار تکراری هم هست ؟؟؟
|
||||
,isnull(nestedLawType.CAPTION,'') as lawType
|
||||
--,isnull(nestedLawStatus.CAPTION,'') as lawStatus
|
||||
,isnull(s.TEXTORDER,0) as textOrder -- ترتیب نمایش مواد و تبصره ها
|
||||
,s.STATENO as stateNo -- ???
|
||||
,isnull(s.SECTIONTYPENO,0) as sectionTypeNumber -- دوهزار رکورد با مقدار صفر دارد اما مقادیر دیگری نیز پذیرفته است ؟؟؟
|
||||
-- بیش از پنج هزار رکورد با مقدار بالاتر از 1500 دارد که چنین مقادیری در جدول سکشن_تایپ وجود ندارد پس با این جدول رابطه ندارد
|
||||
,isnull(l.CAPTION,'') as lawTitle -- عنوان قانون
|
||||
,isnull(l.ID,0) as lawId -- شناسه قانون
|
||||
,isnull(l.APPROVEDATE,'') as aproveDate -- تاریخ تصویب
|
||||
,isnull(l.EXPIREDATE,'') as expireDate -- تاریخ انقضا
|
||||
--,isnull(s.F_LWPHASEID,0) as phaseId -- شناسه فاز
|
||||
,s.FULLPATH as sectionFullPath -- عنوان ماده یا تبصره
|
||||
,isnull(s.SECTIONTYPENOTEXT,'') as sectionType -- ??? استفساریه، کنوانسیون، موافقت نامه، اساسنامه، تفسیر، دوم ، سوم ، چهارم، دوازدهم، خالی، 1، 2، 3، 4
|
||||
,isnull(s.FIRSTSATENO,0) as firstStateNo -- ??? بازه 0 تا 169
|
||||
,isnull(s.LASTSTATENO,0) as lastStateNo -- ??? بازه 0 تا 112
|
||||
,isnull(s.HIERARCHY,'') as hierarchy
|
||||
,isnull(s.DISPLAYINCONTENTS,0) as displayInContents -- ??? صد و پنجاه و سه رکورد دارای مقدار یک و بقیه یک میلیون رکورد مقدار 0 دارد
|
||||
,isnull(s.ISINTERPRETATION,0) as isInterpretation -- ??? چهارصد و پنجاه و سه رکورد با مقدار یک دارد و بقیه مقادیر نال است
|
||||
,(SELECT STRING_AGG(CONVERT(NVARCHAR(max),F_TOPICID), ',') WITHIN GROUP (ORDER BY ID) AS AggregatedResult FROM lwsectiontopic where [F_SECTIONID]=s.id) as topics
|
||||
,l.[ISLAW] -- قانون
|
||||
,l.[ISREGULATION] -- مقرره
|
||||
,l.[ISCORRECTIONLETTER] -- اصلاحیه
|
||||
,(
|
||||
SELECT top (1) p3.CAPTION
|
||||
FROM [lwPhase] p1
|
||||
left join [lwApprover] p2 on p1.ID=p2.F_LWPHASEID
|
||||
left join cmOrganization p3 on p2.F_CMORGANIZATIONID = p3.id
|
||||
where l.ID = p1.F_LWLAWID
|
||||
order by p2.APPROVEDATE asc
|
||||
) as ts_ref -- مرجع تصویب
|
||||
,(
|
||||
SELECT cbt.CAPTION
|
||||
FROM lwLaw l2
|
||||
left JOIN cmBasetable cbt ON l2.[F_LWBASETABLEID_REGULATIONTYPE] = cbt.ID
|
||||
where l.ID = l2.id
|
||||
) as regulationType
|
||||
|
||||
|
||||
from lwSection s
|
||||
left join lwLawSectionStatus lss on s.F_CMBASETABLEID_SECTIONSTATUS = lss.ID
|
||||
left join lwLaw l on s.F_LWLAWID = l.ID
|
||||
left join lwLawSectionStatus lss2 on lss2.id= l.[F_CMBASETABLEID_LASTSTATUS]
|
||||
left JOIN (
|
||||
SELECT l2.F_LWBASETABLEID_LAWTYPE,l2.ID,cbt.CAPTION
|
||||
FROM lwLaw l2
|
||||
left JOIN cmBasetable cbt ON l2.F_LWBASETABLEID_LAWTYPE = cbt.ID
|
||||
) AS nestedLawType ON s.F_LWLAWID = nestedLawType.ID
|
||||
left JOIN (
|
||||
SELECT l2.[F_LWBASETABLEID_REGULATIONTYPE],l2.ID,cbt.CAPTION
|
||||
FROM lwLaw l2
|
||||
left JOIN cmBasetable cbt ON l2.[F_LWBASETABLEID_REGULATIONTYPE] = cbt.ID
|
||||
) AS nestedRegulationType ON s.F_LWLAWID = nestedRegulationType.ID
|
||||
|
||||
where l.[ISREGULATION] = 1
|
||||
order by s.F_LWLAWID,textOrder
|
||||
'''
|
||||
|
||||
|
||||
cursor.execute(query)
|
||||
|
||||
|
||||
url = BASE_URL + "repo/majles/rgsection/multi/add"
|
||||
dict_topic = json.loads(open("list_LWTopic.json").read())
|
||||
|
||||
headers = HEADERS
|
||||
|
||||
bulk_count = 1
|
||||
bulk_data = []
|
||||
|
||||
t1= datetime.datetime.now()
|
||||
print(t1)
|
||||
i = 1
|
||||
while 1:
|
||||
# print(i)
|
||||
i=i+1
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
|
||||
# if i > 1000:
|
||||
# break
|
||||
# print(row.sectionId)
|
||||
|
||||
html = ''
|
||||
if isNeedHtml(row.sectionText) :
|
||||
html = row.sectionText
|
||||
|
||||
try:
|
||||
soup = BeautifulSoup(row.sectionText, "html.parser")
|
||||
text = soup.get_text("\n", strip=True)
|
||||
# text = removeHtmlNoTableTag(row.sectionText) # خطا داره
|
||||
except Exception as e:
|
||||
text = row.sectionText
|
||||
|
||||
text = normalYehKe(text)
|
||||
content_len = text.__len__()
|
||||
|
||||
qanon_title = normalYehKe( row.lawTitle )
|
||||
|
||||
eid='qs'+ str(row.sectionId)
|
||||
|
||||
parentId = '0'
|
||||
if row.parentId != 0 :
|
||||
parentId = 'qs'+ str(row.parentId)
|
||||
lawId='qq'+ str(row.lawId)
|
||||
|
||||
main_type = ''
|
||||
if(row.ISLAW == 1):
|
||||
main_type = 'قانون'
|
||||
elif(row.ISREGULATION == 1):
|
||||
main_type = 'مقرره'
|
||||
|
||||
sub_type = ''
|
||||
if(row.ISLAW == 1):
|
||||
sub_type = row.lawType
|
||||
elif(row.ISREGULATION == 1):
|
||||
sub_type = row.regulationType
|
||||
sub_type = normalYehKe(sub_type)
|
||||
|
||||
# other_type = 'اصلی'
|
||||
# if(row.ISCORRECTIONLETTER == 1):
|
||||
# other_type = 'اصلاحی'
|
||||
|
||||
|
||||
ts_year = ''
|
||||
if row.aproveDate :
|
||||
items = row.aproveDate.split("/")
|
||||
if items.__len__() > 0:
|
||||
ts_year = items[0]
|
||||
|
||||
|
||||
tt = time.time()
|
||||
tt = int( round(tt) * 1000)
|
||||
version_ifo = {
|
||||
"timestamp": tt,
|
||||
"operation": "create",
|
||||
"number" : 1
|
||||
}
|
||||
|
||||
other_info = {
|
||||
"level": row.sectionLevel,
|
||||
"full_path": normalYehKe( row.sectionFullPath ),
|
||||
"number_text":row.sectionType ,
|
||||
"hierarchy" : row.hierarchy
|
||||
}
|
||||
|
||||
topics = []
|
||||
if row.topics:
|
||||
topic_ids = row.topics.split(",")
|
||||
topic_list = list(set(topic_ids))
|
||||
for item in topic_ids:
|
||||
if str(item) in dict_topic:
|
||||
topics.append(
|
||||
{'id': dict_topic[str(item)]['id'], 'title': normalYehKe(dict_topic[str(item)]['title'])}
|
||||
)
|
||||
|
||||
ts_ref = ''
|
||||
if(row.ts_ref):
|
||||
ts_ref = normalYehKe(row.ts_ref)
|
||||
|
||||
|
||||
sort_date_timestamp = -15000000000 # 9/2/1494, 12:45:44 AM # خطا یا خالی
|
||||
try:
|
||||
sort_date_timestamp = getSortTimestamp(row.aproveDate)
|
||||
except Exception as e:
|
||||
sort_date_timestamp = -15000000000 # 9/2/1494, 12:45:44 AM # خطا یا خالی
|
||||
|
||||
expire_date = row.expireDate.strip()
|
||||
|
||||
# state_etebar = normalYehKe(row.lawStatus)
|
||||
state_etebar = normalYehKe(row.sectionStatus)
|
||||
qanon_etebar = ''
|
||||
if row.qanon_etebar :
|
||||
qanon_etebar = row.qanon_etebar
|
||||
|
||||
|
||||
|
||||
data={
|
||||
'id':eid,
|
||||
'ref_id':row.sectionId,
|
||||
'ref_key':'m_qavanin',
|
||||
'main_type': main_type,
|
||||
'sub_type': sub_type,
|
||||
'content': text,
|
||||
'html' : html,
|
||||
'version_info': version_ifo,
|
||||
'qanon_title': qanon_title,
|
||||
'expire_date': expire_date,
|
||||
'ts_date': row.aproveDate,
|
||||
'ts_year': ts_year,
|
||||
'ts_ref': ts_ref,
|
||||
'state_etebar': state_etebar,
|
||||
'qanon_id': lawId,
|
||||
'parent_id': parentId,
|
||||
'child_order': row.textOrder,
|
||||
'other_info': other_info,
|
||||
'content_len': content_len,
|
||||
'topics': topics,
|
||||
'qanon_etebar' : qanon_etebar,
|
||||
#'categories': row.oooo,
|
||||
#'tags': row.oooo,
|
||||
#'keywords': row.oooo,
|
||||
'sort_date_timestamp': sort_date_timestamp, # created from repairQanon.getSortTimestamp
|
||||
}
|
||||
|
||||
if bulk_count > 100:
|
||||
print('=' * 10 )
|
||||
print(str(i)+ ', id=' + eid)
|
||||
print(', lawid=' + lawId)
|
||||
if bulk_count > 0:
|
||||
print(', lawid_first=' + bulk_data[0]['qanon_id'])
|
||||
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
# print(response)
|
||||
bulk_data = []
|
||||
bulk_count = 0
|
||||
# print(response.text)
|
||||
#print(row.txt)
|
||||
|
||||
bulk_data.append(data)
|
||||
bulk_count +=1
|
||||
|
||||
|
||||
|
||||
if bulk_count > 0:
|
||||
print(bulk_count)
|
||||
if bulk_count > 0:
|
||||
print(', lawid_first=' + bulk_data[0]['qanon_id'])
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
|
||||
cursor.close()
|
||||
cnxn.close()
|
||||
print('end success')
|
||||
t2= datetime.datetime.now()
|
||||
print(t2-t1)
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
import json
|
||||
import requests
|
||||
from config_base import *
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from html import escape
|
||||
import json
|
||||
from decimal import Decimal
|
||||
import datetime
|
||||
|
||||
|
||||
from config_base import *
|
||||
from general_functions import *
|
||||
|
||||
# موقت
|
||||
# این برنامه موقتا بخاطر اصلاح داده اجرا شد، اگر از ابتدا انتقال داده انجام شود این بخش خودکار انجام خواهد شد
|
||||
|
||||
cursor, cnxn = create_cursor()
|
||||
|
||||
# Does quasi the same things as json.loads from here: https://pypi.org/project/dynamodb-json/
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, Decimal):
|
||||
return float(obj)
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
||||
#نکته : برای مقررات هیچ موردی نبود که جدولی باشد
|
||||
query = '''
|
||||
SELECT s.ID as sectionId
|
||||
,[SECTIONTEXT] as sectionText
|
||||
FROM [Qavanin].[dbo].[lwSection] s
|
||||
left join lwLaw l on s.F_LWLAWID = l.ID
|
||||
where l.ISLAW = 1 and SECTIONTEXT like '%<TABLE%' or SECTIONTEXT like '%<table%'
|
||||
order by F_LWLAWID, TEXTORDER
|
||||
|
||||
|
||||
'''
|
||||
|
||||
cursor.execute(query)
|
||||
|
||||
|
||||
url = BASE_URL + "repo/majles/section/multi/update"
|
||||
dict_topic = json.loads(open("list_LWTopic.json").read())
|
||||
|
||||
headers = HEADERS
|
||||
|
||||
bulk_count = 1
|
||||
bulk_data = []
|
||||
previd = ''
|
||||
ref_state_array = []
|
||||
|
||||
t1= datetime.datetime.now()
|
||||
print(t1)
|
||||
i = 0
|
||||
while 1:
|
||||
# print(i)
|
||||
i=i+1
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
|
||||
# if i > 3:
|
||||
# break
|
||||
print(row.sectionId)
|
||||
|
||||
# try:
|
||||
# soup = BeautifulSoup(row.sectionText, "html.parser")
|
||||
# text = soup.get_text("\n", strip=True)
|
||||
# # text = removeHtmlNoTableTag(row.sectionText) # خطا داره
|
||||
# except Exception as e:
|
||||
# text = row.sectionText
|
||||
|
||||
# text = normalYehKe(text)
|
||||
|
||||
eid='qs'+ str(row.sectionId)
|
||||
html = row.sectionText
|
||||
|
||||
data={
|
||||
'id' : eid,
|
||||
# 'content': text,
|
||||
'html' : escape(html)
|
||||
}
|
||||
|
||||
if bulk_count > 100:
|
||||
print('=' * 10 )
|
||||
print(str(i)+ ', id=' + eid)
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
print(response)
|
||||
bulk_data = []
|
||||
bulk_count =0
|
||||
# print(response.text)
|
||||
#print(row.txt)
|
||||
|
||||
bulk_data.append(data)
|
||||
bulk_count +=1
|
||||
|
||||
|
||||
print(bulk_count)
|
||||
if bulk_count >= 1:
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
print(response)
|
||||
# print(response.text )
|
||||
|
||||
cursor.close()
|
||||
cnxn.close()
|
||||
print('end success')
|
||||
t2= datetime.datetime.now()
|
||||
print(t2-t1)
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
import json
|
||||
import requests
|
||||
from config_base import *
|
||||
import pyodbc
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from html import escape
|
||||
import json
|
||||
from decimal import Decimal
|
||||
import datetime
|
||||
import sys
|
||||
import traceback
|
||||
import re
|
||||
|
||||
from config_base import *
|
||||
from general_functions import *
|
||||
|
||||
# ضرورتا
|
||||
# این برنامه ضرورت دارد اجرا شود
|
||||
|
||||
cursor, cnxn = create_cursor()
|
||||
|
||||
#Does quasi the same things as json.loads from here: https://pypi.org/project/dynamodb-json/
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, Decimal):
|
||||
return float(obj)
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
||||
|
||||
query = '''
|
||||
SELECT
|
||||
gl1.ID as id,
|
||||
gl4.APPROVEDATE as effect_Date,
|
||||
gl3.[SECTIONTEXT] as effect_text,
|
||||
gl3.FULLPATH as effect_section_title,
|
||||
ls2.SECTIONTEXT as effect_prev_text,
|
||||
gl4.CAPTION as effect_qanon,
|
||||
gl1.F_LWLAWID_EFFECTIVE as effect_qanon_id,
|
||||
gl1.[F_LWSECTIONID_EFFECTIVE] as effect_section_id,
|
||||
gl1.[F_LWSECTIONID_EFFECTED] as sectionId,
|
||||
gl2.[SECTIONTEXT],
|
||||
ls1.CAPTION as effect_section_type,
|
||||
gl1.DESCRIPTION as description,
|
||||
gl1.ISIMPLICIT -- تاثیر ضمنی
|
||||
FROM [Qavanin].[dbo].[lwSectionChange] gl1
|
||||
left join [lwLawSectionStatus] ls1 on ls1.ID=gl1.[F_CMBASETABLEID_SECTIONSTATUS]
|
||||
left join lwSection gl2 on gl2.ID=gl1.[F_LWSECTIONID_EFFECTED]
|
||||
left join lwSection gl3 on gl3.ID=gl1.[F_LWSECTIONID_EFFECTIVE]
|
||||
left join lwLaw gl4 on gl1.F_LWLAWID_EFFECTIVE=gl4.ID
|
||||
left join lwSectionLog ls2 on ls2.ID=gl1.[F_LWSECTIONLOGID_EFFECTED]
|
||||
|
||||
where
|
||||
gl4.ISLAW = 1
|
||||
and gl1.[F_LWSECTIONID_EFFECTED] is not null
|
||||
|
||||
order by gl1.[F_LWSECTIONID_EFFECTED], gl4.APPROVEDATE
|
||||
|
||||
'''
|
||||
# ar = []
|
||||
# for i,item in enumerate(str):
|
||||
# if item == ' ':
|
||||
# print(i)
|
||||
# ar.append(i)
|
||||
# print(len(str.strip().split()))
|
||||
cursor.execute(query)
|
||||
|
||||
|
||||
url = BASE_URL + "repo/majles/section/multi/update"
|
||||
dict_topic = json.loads(open("list_LWTopic.json").read())
|
||||
|
||||
headers = HEADERS
|
||||
|
||||
bulk_count = 1
|
||||
bulk_data = []
|
||||
previd = ''
|
||||
prev_effect_type = ''
|
||||
prev_efect_section_id = ''
|
||||
ref_state_array = []
|
||||
|
||||
t1= datetime.datetime.now()
|
||||
print(t1)
|
||||
i = 0
|
||||
while 1:
|
||||
# print(i)
|
||||
i=i+1
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
|
||||
# if i > 3:
|
||||
# break
|
||||
# print(row.sectionId)
|
||||
|
||||
eid='qs'+ str(row.sectionId)
|
||||
# lawId='qq'+ str(row.lawId)
|
||||
|
||||
if previd == '':
|
||||
previd = eid
|
||||
|
||||
effect_type = ''
|
||||
if row.effect_section_type == 'معتبر' :
|
||||
effect_type = ''
|
||||
elif row.effect_section_type == 'ساختار الحاقي' or row.effect_section_type == 'ساختار الحاقي مكرر' :
|
||||
effect_type = 'الحاقی'
|
||||
elif row.effect_section_type == 'اصلاحي' or row.effect_section_type == 'نامه اصلاحي':
|
||||
effect_type = 'اصلاحی'
|
||||
elif row.effect_section_type == 'منسوخه' :
|
||||
effect_type = 'نسخی'
|
||||
elif row.effect_section_type == 'احياء' or row.effect_section_type == 'تنفيذ' or row.effect_section_type == 'تمديد':
|
||||
effect_type = 'تمدیدی'
|
||||
elif row.effect_section_type == 'تفسير' :
|
||||
effect_type = 'تفسیری'
|
||||
elif row.effect_section_type == 'ساختار جايگزين' or row.effect_section_type == 'جايگزين شده':
|
||||
effect_type = 'جایگزین'
|
||||
elif row.effect_section_type == 'آزمايشي' :
|
||||
effect_type = ''
|
||||
elif row.effect_section_type == 'موقت' :
|
||||
effect_type = ''
|
||||
elif row.effect_section_type == 'موقوف الاجراء' :
|
||||
effect_type = ''
|
||||
elif row.effect_section_type == 'بااجرامنتفي مي شود' :
|
||||
effect_type = ''
|
||||
|
||||
if row.ISIMPLICIT :
|
||||
effect_type += ' ضمنی'
|
||||
|
||||
# if i == 1 : # اولین بار
|
||||
# prev_effect_type = effect_type
|
||||
|
||||
ref_state = {}
|
||||
if row.effect_qanon_id :
|
||||
efect_section_id='qs'+ str(row.effect_section_id)
|
||||
efect_qanon_id= 'qq'+ str(row.effect_qanon_id)
|
||||
|
||||
if prev_efect_section_id == '' :
|
||||
prev_efect_section_id = efect_section_id
|
||||
|
||||
ref_state = {
|
||||
"id" : row.id,
|
||||
"qanon_id": efect_qanon_id,
|
||||
"qanon_title" : normalYehKe(row.effect_qanon),
|
||||
"qanon_date": row.effect_Date,
|
||||
"section_id": efect_section_id,
|
||||
"section_title": normalYehKe(row.effect_section_title),
|
||||
"ref_key": "qavanin",
|
||||
"effect_type" : effect_type,
|
||||
"new_text" : normalYehKe(row.effect_text),
|
||||
"prev_text" : normalYehKe(row.effect_prev_text),
|
||||
"description" : normalYehKe(row.description)
|
||||
}
|
||||
|
||||
|
||||
if previd == eid :
|
||||
# موارد کاملا تکراری افزوده نشود
|
||||
if efect_section_id != prev_efect_section_id or prev_effect_type != effect_type:
|
||||
ref_state_array.append(ref_state)
|
||||
prev_efect_section_id = efect_section_id
|
||||
prev_effect_type = effect_type
|
||||
ref_state={}
|
||||
continue
|
||||
|
||||
|
||||
data={
|
||||
'id' : previd,
|
||||
'ref_state' : ref_state_array
|
||||
}
|
||||
|
||||
bulk_data.append(data)
|
||||
bulk_count +=1
|
||||
|
||||
ref_state_array = []
|
||||
previd = eid
|
||||
prev_efect_section_id = efect_section_id
|
||||
prev_effect_type = effect_type
|
||||
ref_state_array.append(ref_state)
|
||||
|
||||
if bulk_data.__len__() > 100:
|
||||
print('=' * 10 )
|
||||
print(str(i)+ ', id=' + eid)
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
print(response)
|
||||
bulk_data = []
|
||||
bulk_count = 1
|
||||
# print(response.text)
|
||||
#print(row.txt)
|
||||
|
||||
|
||||
|
||||
|
||||
if ref_state_array.__len__() > 0 :
|
||||
data={
|
||||
'id' : previd,
|
||||
'ref_state' : ref_state_array
|
||||
}
|
||||
bulk_data.append(data)
|
||||
# print(bulk_data)
|
||||
|
||||
if bulk_data.__len__() > 0:
|
||||
print(bulk_count)
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
# print(response.text)
|
||||
|
||||
cursor.close()
|
||||
cnxn.close()
|
||||
print('end success')
|
||||
t2= datetime.datetime.now()
|
||||
print(t2-t1)
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
import json
|
||||
import requests
|
||||
from config_base import *
|
||||
import pyodbc
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from html import escape
|
||||
import json
|
||||
from decimal import Decimal
|
||||
import datetime
|
||||
import sys
|
||||
import traceback
|
||||
import re
|
||||
|
||||
from config_base import *
|
||||
from general_functions import *
|
||||
|
||||
# ضرورتا
|
||||
# این برنامه ضرورت دارد اجرا شود
|
||||
|
||||
cursor, cnxn = create_cursor()
|
||||
|
||||
#Does quasi the same things as json.loads from here: https://pypi.org/project/dynamodb-json/
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, Decimal):
|
||||
return float(obj)
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
||||
|
||||
query = '''
|
||||
SELECT
|
||||
gl1.ID as id,
|
||||
gl4.APPROVEDATE as effect_Date,
|
||||
gl3.[SECTIONTEXT] as effect_text,
|
||||
gl3.FULLPATH as effect_section_title,
|
||||
ls2.SECTIONTEXT as effect_prev_text,
|
||||
gl4.CAPTION as effect_qanon,
|
||||
gl1.F_LWLAWID_EFFECTIVE as effect_qanon_id,
|
||||
gl1.[F_LWSECTIONID_EFFECTIVE] as effect_section_id,
|
||||
gl1.[F_LWSECTIONID_EFFECTED] as sectionId,
|
||||
gl2.[SECTIONTEXT],
|
||||
ls1.CAPTION as effect_section_type,
|
||||
gl1.DESCRIPTION as description,
|
||||
gl1.ISIMPLICIT -- تاثیر ضمنی
|
||||
FROM [Qavanin].[dbo].[lwSectionChange] gl1
|
||||
left join [lwLawSectionStatus] ls1 on ls1.ID=gl1.[F_CMBASETABLEID_SECTIONSTATUS]
|
||||
left join lwSection gl2 on gl2.ID=gl1.[F_LWSECTIONID_EFFECTED]
|
||||
left join lwSection gl3 on gl3.ID=gl1.[F_LWSECTIONID_EFFECTIVE]
|
||||
left join lwLaw gl4 on gl1.F_LWLAWID_EFFECTIVE=gl4.ID
|
||||
left join lwSectionLog ls2 on ls2.ID=gl1.[F_LWSECTIONLOGID_EFFECTED]
|
||||
|
||||
where
|
||||
gl4.[ISREGULATION] = 1
|
||||
and gl1.[F_LWSECTIONID_EFFECTED] is not null
|
||||
|
||||
order by gl1.[F_LWSECTIONID_EFFECTED], gl4.APPROVEDATE
|
||||
|
||||
'''
|
||||
# ar = []
|
||||
# for i,item in enumerate(str):
|
||||
# if item == ' ':
|
||||
# print(i)
|
||||
# ar.append(i)
|
||||
# print(len(str.strip().split()))
|
||||
cursor.execute(query)
|
||||
|
||||
|
||||
url = BASE_URL + "repo/majles/rgsection/multi/update"
|
||||
dict_topic = json.loads(open("list_LWTopic.json").read())
|
||||
|
||||
headers = HEADERS
|
||||
|
||||
bulk_count = 1
|
||||
bulk_data = []
|
||||
previd = ''
|
||||
prev_effect_type = ''
|
||||
prev_efect_section_id = ''
|
||||
ref_state_array = []
|
||||
|
||||
t1= datetime.datetime.now()
|
||||
print(t1)
|
||||
i = 0
|
||||
while 1:
|
||||
# print(i)
|
||||
i=i+1
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
|
||||
# if i > 3:
|
||||
# break
|
||||
# print(row.sectionId)
|
||||
|
||||
eid='qs'+ str(row.sectionId)
|
||||
# lawId='qq'+ str(row.lawId)
|
||||
|
||||
if previd == '':
|
||||
previd = eid
|
||||
|
||||
effect_type = ''
|
||||
if row.effect_section_type == 'معتبر' :
|
||||
effect_type = ''
|
||||
elif row.effect_section_type == 'ساختار الحاقي' or row.effect_section_type == 'ساختار الحاقي مكرر' :
|
||||
effect_type = 'الحاقی'
|
||||
elif row.effect_section_type == 'اصلاحي' or row.effect_section_type == 'نامه اصلاحي':
|
||||
effect_type = 'اصلاحی'
|
||||
elif row.effect_section_type == 'منسوخه' :
|
||||
effect_type = 'نسخی'
|
||||
elif row.effect_section_type == 'احياء' or row.effect_section_type == 'تنفيذ' or row.effect_section_type == 'تمديد':
|
||||
effect_type = 'تمدیدی'
|
||||
elif row.effect_section_type == 'تفسير' :
|
||||
effect_type = 'تفسیری'
|
||||
elif row.effect_section_type == 'ساختار جايگزين' or row.effect_section_type == 'جايگزين شده':
|
||||
effect_type = 'جایگزین'
|
||||
elif row.effect_section_type == 'آزمايشي' :
|
||||
effect_type = ''
|
||||
elif row.effect_section_type == 'موقت' :
|
||||
effect_type = ''
|
||||
elif row.effect_section_type == 'موقوف الاجراء' :
|
||||
effect_type = ''
|
||||
elif row.effect_section_type == 'بااجرامنتفي مي شود' :
|
||||
effect_type = ''
|
||||
|
||||
if row.ISIMPLICIT :
|
||||
effect_type += ' ضمنی'
|
||||
|
||||
# if i == 1 : # اولین بار
|
||||
# prev_effect_type = effect_type
|
||||
|
||||
ref_state = {}
|
||||
if row.effect_qanon_id :
|
||||
efect_section_id='qs'+ str(row.effect_section_id)
|
||||
efect_qanon_id= 'qq'+ str(row.effect_qanon_id)
|
||||
|
||||
if prev_efect_section_id == '' :
|
||||
prev_efect_section_id = efect_section_id
|
||||
|
||||
ref_state = {
|
||||
"id" : row.id,
|
||||
"qanon_id": efect_qanon_id,
|
||||
"qanon_title" : normalYehKe(row.effect_qanon),
|
||||
"qanon_date": row.effect_Date,
|
||||
"section_id": efect_section_id,
|
||||
"section_title": normalYehKe(row.effect_section_title),
|
||||
"ref_key": "qavanin",
|
||||
"effect_type" : effect_type,
|
||||
"new_text" : normalYehKe(row.effect_text),
|
||||
"prev_text" : normalYehKe(row.effect_prev_text),
|
||||
"description" : normalYehKe(row.description)
|
||||
}
|
||||
|
||||
|
||||
if previd == eid :
|
||||
# موارد کاملا تکراری افزوده نشود
|
||||
if efect_section_id != prev_efect_section_id or prev_effect_type != effect_type:
|
||||
ref_state_array.append(ref_state)
|
||||
prev_efect_section_id = efect_section_id
|
||||
prev_effect_type = effect_type
|
||||
ref_state={}
|
||||
continue
|
||||
|
||||
|
||||
data={
|
||||
'id' : previd,
|
||||
'ref_state' : ref_state_array
|
||||
}
|
||||
|
||||
bulk_data.append(data)
|
||||
bulk_count +=1
|
||||
|
||||
ref_state_array = []
|
||||
previd = eid
|
||||
prev_efect_section_id = efect_section_id
|
||||
prev_effect_type = effect_type
|
||||
ref_state_array.append(ref_state)
|
||||
|
||||
if bulk_data.__len__() > 100:
|
||||
print('=' * 10 )
|
||||
print(str(i)+ ', id=' + eid)
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
print(response)
|
||||
bulk_data = []
|
||||
bulk_count = 1
|
||||
# print(response.text)
|
||||
#print(row.txt)
|
||||
|
||||
|
||||
|
||||
|
||||
if ref_state_array.__len__() > 0 :
|
||||
data={
|
||||
'id' : previd,
|
||||
'ref_state' : ref_state_array
|
||||
}
|
||||
bulk_data.append(data)
|
||||
# print(bulk_data)
|
||||
|
||||
if bulk_data.__len__() > 0:
|
||||
print(bulk_count)
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
# print(response.text)
|
||||
|
||||
cursor.close()
|
||||
cnxn.close()
|
||||
print('end success')
|
||||
t2= datetime.datetime.now()
|
||||
print(t2-t1)
|
||||
|
||||
@@ -0,0 +1,225 @@
|
||||
import json
|
||||
import requests
|
||||
from config_base import *
|
||||
import pyodbc
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from html import escape
|
||||
import json
|
||||
from decimal import Decimal
|
||||
import datetime
|
||||
import sys
|
||||
import traceback
|
||||
import re
|
||||
|
||||
from config_base import *
|
||||
from general_functions import *
|
||||
|
||||
# این برنامه یک بار فقط جهت انتقال کدهای دیتابیس آقای شاهنوش به دیتابیس نهایی قوانین انجام شد
|
||||
# تکرار لازم نیست
|
||||
|
||||
cursor, cnxn = create_cursor('db4minaei')
|
||||
|
||||
#Does quasi the same things as json.loads from here: https://pypi.org/project/dynamodb-json/
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, Decimal):
|
||||
return float(obj)
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
||||
|
||||
plan1 = {}
|
||||
query = """select * from dbo.[lwplan] where [f_parentid]=766 order by [ordno] """
|
||||
cursor.execute(query)
|
||||
i = 0
|
||||
while 1:
|
||||
i=i+1
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
plan1[row.ID] = normalYehKe(row.caption)
|
||||
|
||||
# print(plan1)
|
||||
|
||||
plan2 = {}
|
||||
query = """select * from dbo.[lwplan] where [f_parentid]=21185 order by [ordno] """
|
||||
cursor.execute(query)
|
||||
i = 0
|
||||
while 1:
|
||||
i=i+1
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
plan2[row.ID] = normalYehKe(row.caption)
|
||||
|
||||
# print(plan2)
|
||||
|
||||
# #########################################################
|
||||
|
||||
query = '''
|
||||
SELECT [f_lwplanid]
|
||||
,[f_lwlawsecid]
|
||||
,[planstate]
|
||||
,[ID]
|
||||
FROM [db4minaei].[dbo].[lwlawplan]
|
||||
where f_lwlawsecid is not null and f_lwlawsecid > 0
|
||||
order by f_lwlawsecid, planstate, f_lwplanid
|
||||
|
||||
'''
|
||||
|
||||
cursor.execute(query)
|
||||
|
||||
|
||||
url = BASE_URL + "repo/majles/section/multi/update"
|
||||
dict_topic = json.loads(open("list_LWTopic.json").read())
|
||||
|
||||
headers = HEADERS
|
||||
|
||||
bulk_count = 1
|
||||
bulk_data = []
|
||||
previd = ''
|
||||
|
||||
tcode_main_old = []
|
||||
tcode_sub_old = []
|
||||
tcode_main = []
|
||||
tcode_sub = []
|
||||
prev_sectionid = 0
|
||||
prev_planid = 0
|
||||
prev_planstate = 0
|
||||
|
||||
prev2_sectionid = 0
|
||||
prev2_planid = 0
|
||||
prev2_planstate = 0
|
||||
|
||||
t1= datetime.datetime.now()
|
||||
print(t1)
|
||||
i = 0
|
||||
while 1:
|
||||
# print(i)
|
||||
i=i+1
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
|
||||
# if i > 3:
|
||||
# break
|
||||
# print(row.sectionId)
|
||||
|
||||
sectionid = row.f_lwlawsecid
|
||||
planid = row.f_lwplanid
|
||||
planstate = row.planstate
|
||||
|
||||
if prev_sectionid == 0 :
|
||||
prev_sectionid = sectionid
|
||||
prev_planid = planid
|
||||
prev_planstate = planstate
|
||||
continue
|
||||
|
||||
|
||||
if sectionid == prev_sectionid and planid == prev_planid and planstate == prev_planstate :
|
||||
continue
|
||||
|
||||
|
||||
if sectionid == prev_sectionid :
|
||||
if prev_planid in plan1 :
|
||||
if prev_planstate == 1 :
|
||||
tcode_main_old.append(plan1[prev_planid])
|
||||
else :
|
||||
tcode_sub_old.append(plan1[prev_planid])
|
||||
|
||||
|
||||
elif prev_planid in plan2 :
|
||||
if prev_planstate == 1 :
|
||||
tcode_main.append(plan2[prev_planid])
|
||||
else :
|
||||
tcode_sub.append(plan2[prev_planid])
|
||||
prev_planid = planid
|
||||
prev_planstate = planstate
|
||||
continue
|
||||
|
||||
|
||||
eid='qs'+ str(prev_sectionid)
|
||||
data={
|
||||
'id' : eid,
|
||||
'tcode_main' : tcode_main,
|
||||
'tcode_sub' : tcode_sub,
|
||||
'tcode_main_old' : tcode_main_old,
|
||||
'tcode_sub_old' : tcode_sub_old,
|
||||
}
|
||||
|
||||
# print(eid)
|
||||
|
||||
bulk_data.append(data)
|
||||
bulk_count +=1
|
||||
prev_sectionid = sectionid
|
||||
tcode_main_old = []
|
||||
tcode_sub_old = []
|
||||
tcode_main = []
|
||||
tcode_sub = []
|
||||
|
||||
if bulk_data.__len__() > 100:
|
||||
print('=' * 10 )
|
||||
print(str(i)+ ', id=' + eid)
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
# print(response.text)
|
||||
bulk_data = []
|
||||
bulk_count = 1
|
||||
# print(payload)
|
||||
|
||||
# print(response.text)
|
||||
#print(row.txt)
|
||||
|
||||
# /////////////////
|
||||
prev2_sectionid = prev_sectionid
|
||||
prev2_planid = prev_planid
|
||||
prev2_planstate = prev_planstate
|
||||
|
||||
prev_sectionid = sectionid
|
||||
prev_planid = planid
|
||||
prev_planstate = planstate
|
||||
|
||||
|
||||
|
||||
|
||||
# if prev2_sectionid == prev_sectionid :
|
||||
if prev_planid in plan1 :
|
||||
if prev_planstate == 1 :
|
||||
tcode_main_old.append(plan1[prev_planid])
|
||||
else :
|
||||
tcode_sub_old.append(plan1[prev_planid])
|
||||
|
||||
|
||||
elif prev_planid in plan2 :
|
||||
if prev_planstate == 1 :
|
||||
tcode_main.append(plan2[prev_planid])
|
||||
else :
|
||||
tcode_sub.append(plan2[prev_planid])
|
||||
# else :
|
||||
|
||||
|
||||
eid='qs'+ str(prev_sectionid)
|
||||
data={
|
||||
'id' : eid,
|
||||
'tcode_main' : tcode_main,
|
||||
'tcode_sub' : tcode_sub,
|
||||
'tcode_main_old' : tcode_main_old,
|
||||
'tcode_sub_old' : tcode_sub_old,
|
||||
}
|
||||
|
||||
bulk_data.append(data)
|
||||
bulk_count +=1
|
||||
|
||||
if bulk_data.__len__() > 0:
|
||||
print(' *** end bulk count ' , bulk_count)
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
|
||||
# print(response.text)
|
||||
|
||||
cursor.close()
|
||||
cnxn.close()
|
||||
print('end success')
|
||||
t2= datetime.datetime.now()
|
||||
print(t2-t1)
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
|
||||
# با این متد، داده های بانک اسکیوال خوانده می شود
|
||||
def qavanin_treetext_read(startValue,count):
|
||||
cursor = create_cursor()
|
||||
|
||||
|
||||
query = 'SELECT * FROM qavanin.qavanin_treetext limit %s , %s'
|
||||
# مقادیری که باید در کوئری بالا جایگزین شود
|
||||
vals = (startValue,count)
|
||||
conn = dbm.ConnectionClass('','','','')
|
||||
result = dbm.executeQueryRead(conn,query,vals)
|
||||
return result
|
||||
|
||||
# در این متد، رکورد جدول اسکیوال به یک رکورد جیسون تبدیل می شود
|
||||
def getDataRecord(record):
|
||||
dataRecord = {
|
||||
'id': 'qavanin_ir_' + str(record[5]),
|
||||
'title':str(record[1]),
|
||||
'content':str(record[2]),
|
||||
'ref_url':'https://qavanin.ir/Law/TreeText/'+str(record[3]),
|
||||
'ts_date':str(record[4]),
|
||||
'ref_id':str(record[3])
|
||||
}
|
||||
|
||||
return dataRecord
|
||||
|
||||
# این متد، داده های دریافت شده از بانک اسکیوال را در یک حلقه می اندازد
|
||||
# و آرایه ای از جیسون که در واقع همان
|
||||
# bulk_data
|
||||
# است را پر می کند
|
||||
def elasticBuckIndex(records):
|
||||
# Elasticsearch settings
|
||||
es_url = "https://api.tavasi.ir/repo/majles/qqanon/multi/add"
|
||||
# نام ایندکس(جدولی) که اطلاعات در آن ذخیره می شود
|
||||
es_index = "my_index"
|
||||
|
||||
# Bulk index the data
|
||||
bulk_data = []
|
||||
|
||||
for dataRecord in records:
|
||||
# ایجاد یک رکورد دیتا برای الاستیک
|
||||
data = getDataRecord(dataRecord)
|
||||
# اضافه کردن دیتا رکورد ایجاد شده به دیتاباک
|
||||
bulk_data.append(data)
|
||||
|
||||
|
||||
elastic_data = json.dumps(bulk_data)
|
||||
|
||||
# Send the bulk request
|
||||
response = requests.post(f"{es_url}", headers=HEADERS, data=elastic_data, timeout=600000)
|
||||
print(response.text)
|
||||
|
||||
# متد اصلی که توابع دیگر را فراخوانی می کند
|
||||
def main():
|
||||
index = 0
|
||||
x = 0
|
||||
for i in range(1,1160):
|
||||
# دریافت 10 تا رکورد از جدول قوانین
|
||||
records = qavanin_treetext_read(index,10)
|
||||
|
||||
# to elastic records
|
||||
elasticBuckIndex(records)
|
||||
|
||||
index = i * 10
|
||||
i = i + 1
|
||||
x += len(records)
|
||||
|
||||
print('تعداد رکوردهای اضافه شده به الاستیک : ' + str(x))
|
||||
print('end success')
|
||||
|
||||
# اجرای کدها ...
|
||||
#main()
|
||||
@@ -0,0 +1,93 @@
|
||||
import requests
|
||||
import json
|
||||
from general_functions import *
|
||||
cursor = create_cursor()
|
||||
|
||||
# -----------------------------------------------------------------
|
||||
|
||||
|
||||
BASE_URL = "https://api.tavasi.ir/list/"
|
||||
ADD_LIST_ROUTE = "project/add"
|
||||
ADD_ITEM_ROUTE = "subject/add"
|
||||
TITLE = "موضوعات قانونی"
|
||||
TYPE = 3
|
||||
ADD_LIST_QUERY = {"title": TITLE, "type": TYPE, "item_state": 1}
|
||||
GET_H = lambda x: x["HIERARCHY"]
|
||||
GET_F = lambda x: x["F_PARENTID"]
|
||||
projectid = 1
|
||||
|
||||
EXAMPLE_ADD_ITEM_QUERY = {
|
||||
"title": "",
|
||||
"projectid": projectid,
|
||||
"listtype": 0,
|
||||
"parent": 0,
|
||||
}
|
||||
|
||||
# print(requests.post(BASE_URL + ADD_LIST_ROUTE, data=ADD_LIST_QUERY, headers = HEADERS).text)
|
||||
|
||||
IDS_DICT = {}
|
||||
|
||||
query = """select * from dbo.lwtopic"""
|
||||
cursor.execute(query)
|
||||
|
||||
|
||||
result = []
|
||||
|
||||
while True:
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
|
||||
HIERARCHY = row.HIERARCHY
|
||||
HIERARCHY = HIERARCHY.split(".")[-2]
|
||||
HIERARCHY = HIERARCHY.rjust(3, "0")
|
||||
|
||||
result.append(
|
||||
{
|
||||
"ID": int(row.ID),
|
||||
"CAPTION": row.CAPTION,
|
||||
"F_PARENTID": int(row.F_PARENTID) if row.F_PARENTID else 0,
|
||||
"HIERARCHY": HIERARCHY,
|
||||
}
|
||||
)
|
||||
# result = sorted(result, key=GET_F)
|
||||
result = sorted(result, key=GET_H)
|
||||
|
||||
for i in range(0, 195):
|
||||
number = 1
|
||||
for row in result:
|
||||
if not row:
|
||||
continue
|
||||
|
||||
try:
|
||||
parent = IDS_DICT[str(i)]['id']
|
||||
except KeyError:
|
||||
parent = 0
|
||||
|
||||
try:
|
||||
F_PARENTID = row["F_PARENTID"]
|
||||
except KeyError:
|
||||
F_PARENTID = -1
|
||||
# print('*'*20)
|
||||
# print(row)
|
||||
# print('#'*20)
|
||||
continue
|
||||
|
||||
if F_PARENTID == i : # or (i == 0 and row["F_PARENTID"] == None)
|
||||
ADD_ITEM_QUERY = {
|
||||
"title": row["CAPTION"],
|
||||
"projectid": projectid,
|
||||
"otherid": row["ID"],
|
||||
"childorder": number,
|
||||
"listtype": 0,
|
||||
"parent": parent,
|
||||
}
|
||||
number += 1
|
||||
result = requests.post(BASE_URL + ADD_ITEM_ROUTE, data=ADD_ITEM_QUERY, headers=HEADERS)
|
||||
|
||||
ID = json.loads(result.text)["data"][0]["id"]
|
||||
print(ID)
|
||||
IDS_DICT[str(row["ID"])] = {"id" : int(ID), 'title': row["CAPTION"]}
|
||||
|
||||
with open("list_LWTopic.json", 'w') as file:
|
||||
file.write(json.dumps(IDS_DICT))
|
||||
@@ -0,0 +1,106 @@
|
||||
import requests
|
||||
import pyodbc
|
||||
import json
|
||||
from decimal import Decimal
|
||||
from general_functions import *
|
||||
cursor = create_cursor()
|
||||
|
||||
url = "https://api.tavasi.ir/keyvalue/list/add"
|
||||
|
||||
headers = {
|
||||
"Accept": ACCEPT,
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
"Authorization": TOKEN,
|
||||
}
|
||||
|
||||
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, Decimal):
|
||||
return float(obj)
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
||||
|
||||
IDS_DICT = dict()
|
||||
|
||||
aLambdaMethod = lambda x: str(x * 10)
|
||||
|
||||
query = """
|
||||
SELECT l.ID
|
||||
,l.SUBJECT
|
||||
,l2.CAPTION
|
||||
,l.OPINIONDATE
|
||||
,[ARCHIVENO]
|
||||
,[F_CMBASETABLEID_CLASSIFICATION]
|
||||
,[F_OPOPINIONGIVERID]
|
||||
,[F_LWLAWID]
|
||||
,[DISTRIBUTENO]
|
||||
,[DISTRIBUTEDATE]
|
||||
,isnull((select top(1) DOCTEXT from prdoc where id=l.[F_PRDOCID] ),'') as content
|
||||
,(select STRING_AGG([F_LWTOPICID], ',') from [opopiniontopic] where [F_OPOPINIONID]=l.id) as topics
|
||||
FROM dbo.opopinion l
|
||||
left join dbo.lwlaw l2 on l.F_LWLAWID=l2.id
|
||||
"""
|
||||
|
||||
|
||||
cursor.execute(query)
|
||||
|
||||
|
||||
url = "https://api.tavasi.ir/repo/majles/temp/add"
|
||||
|
||||
i = 0
|
||||
|
||||
# while True:
|
||||
while (
|
||||
len(
|
||||
str(
|
||||
(
|
||||
len(
|
||||
str(
|
||||
aLambdaMethod(
|
||||
len(
|
||||
str(
|
||||
str(i)
|
||||
.replace(" ", "")
|
||||
.split(" ")
|
||||
.__class__.__name__.__len__
|
||||
)
|
||||
)
|
||||
).__class__.__name__.__len__
|
||||
)
|
||||
)
|
||||
> 0
|
||||
)
|
||||
).__class__.__name__
|
||||
)
|
||||
!= len(
|
||||
str(__file__.__class__.__name__ != __name__)
|
||||
).__init_subclass__.__class__.__name__.__len__
|
||||
):
|
||||
print(i)
|
||||
i += 1
|
||||
row = cursor.fetchone()
|
||||
|
||||
if not row:
|
||||
break
|
||||
|
||||
eid = "mj_mtaghnin_" + str(row.ID)
|
||||
|
||||
data = {
|
||||
"id": eid,
|
||||
"ref_id": row.ID,
|
||||
"content": row.CAPTION if row.CAPTION else row.CAPTION2,
|
||||
"opinion_date": row.OPINIONDATE,
|
||||
"classification": row.F_CMBASETABLEID_CLASSIFICATION,
|
||||
"F_LWLAWID": row.F_LWLAWID,
|
||||
"publish_no": row.DISTRIBUTENO,
|
||||
"publish_date": row.DISTRIBUTEDATE,
|
||||
"archive_no": row.ARCHIVENO,
|
||||
"topics": row.topics,
|
||||
"opinion_giver": row.F_OPOPINIONGIVERID,
|
||||
"content": row.content,
|
||||
}
|
||||
|
||||
payload = json.dumps(data, cls=JSONEncoder) # Works!
|
||||
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
@@ -0,0 +1,77 @@
|
||||
import pyodbc
|
||||
import requests
|
||||
from html import escape
|
||||
import json
|
||||
from decimal import Decimal
|
||||
from general_functions import *
|
||||
|
||||
cursor = create_cursor()
|
||||
|
||||
|
||||
# Does quasi the same things as json.loads from here: https://pypi.org/project/dynamodb-json/
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, Decimal):
|
||||
return float(obj)
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
||||
|
||||
# cursor.execute("SELECT @@VERSION;")
|
||||
|
||||
# dict_cmbasetable = json.loads(open("list_cmbasetable.json").read())
|
||||
|
||||
|
||||
|
||||
query = """select l.id as ref_id,l.CAPTION as title
|
||||
,isnull(t.caption,'') as type1
|
||||
,isnull(ls.caption,'') as status1
|
||||
,isnull(lt.caption,'') as tanghih
|
||||
,isnull(co.CAPTION,'') as ts_ref
|
||||
,isnull([EXPIREDATE],'') as exp_date
|
||||
,isnull([majlesno],'') as majlesno
|
||||
,isnull(APPROVEDATE,'') as ts_date
|
||||
,isnull([APPROVEDATELast],'') as ts_date_last
|
||||
,isnull((select top(1) txt from lwlawtext where f_lwlawid=l.id order by f_lwphaseid desc ),'') as content
|
||||
,(select STRING_AGG(F_CMORGANIZATIONID, ',') from [lwexecutor] where F_LWLAWID=l.id) as exceuter_CMORGANIZATION
|
||||
,(select STRING_AGG(F_CMORGANIZATIONID, ',') from [lwreceiver] where F_LWLAWID=l.id) as receiver_CMORGANIZATION
|
||||
from lwlaw l
|
||||
left join lwlawtype t on l.[f_lwlawtypeid]=t.id
|
||||
left join lwlawstatus ls on l.[f_lwlawstatusid] = ls.id
|
||||
left join lwlawtanghih lt on l.[f_lwlawtanghihid] = lt.id
|
||||
left join cmorganization co on l.[F_CMORGANIZATIONIDApprover]=co.id"""
|
||||
|
||||
|
||||
cursor.execute(query)
|
||||
|
||||
|
||||
url = "https://api.tavasi.ir/repo/majles/temp/add"
|
||||
|
||||
headers = HEADERS
|
||||
|
||||
|
||||
i = 1
|
||||
while 1:
|
||||
print(i)
|
||||
i = i + 1
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
# if row.ref_id > 1000:
|
||||
# break
|
||||
eid = "mj_mtaghnin_" + str(row.ref_id)
|
||||
|
||||
data = {
|
||||
"eid": eid,
|
||||
"exceuter_CMORGANIZATION": row.exceuter_CMORGANIZATION,
|
||||
"receiver_CMORGANIZATION": row.receiver_CMORGANIZATION,
|
||||
}
|
||||
|
||||
payload = json.dumps(data, cls=JSONEncoder) # Works!
|
||||
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
|
||||
# print(response.text)
|
||||
# print(row.txt)
|
||||
cursor.close()
|
||||
cnxn.close()
|
||||
print("end success")
|
||||
@@ -0,0 +1,267 @@
|
||||
----------------------------
|
||||
[bayanieh] -- استانها --- خالی
|
||||
[bayanieh] -- بیانیه --- خالی
|
||||
|
||||
[tarh] -- خالی
|
||||
[tarh_commission] --خالی
|
||||
[tazakorK] --خالی
|
||||
[tazakorS] --خالی
|
||||
[visitor] -- خالی
|
||||
test -- خالی تست
|
||||
[visitorUrl] -- خالی
|
||||
|
||||
[candid_Comission] -- خالی
|
||||
[candid_bayanieh] -- خالی
|
||||
candid_estizah -- خالی
|
||||
candid_etemad -- 2 خالی
|
||||
[candid_question] -- خالی 2 مورد
|
||||
[candid_tarh] -- خالی
|
||||
[candid_tazakorK] -- خالی
|
||||
[layeheh] -- خالی
|
||||
[minister_layeheh] -- خالی
|
||||
[notgh] -- خالی
|
||||
[question] --خالی
|
||||
|
||||
|
||||
[content_candid] -- خالی
|
||||
[dastur_tag] -- خالی
|
||||
[estizah] -- خالی
|
||||
[etemad] -- خالی
|
||||
[media] -- به نظر تستی هست
|
||||
[logPDFUpload] -- به نظر تستی هست
|
||||
|
||||
---------------------------------------
|
||||
|
||||
|
||||
/****** Script for SelectTopNRows command from SSMS ******/
|
||||
SELECT [ID]
|
||||
,[Title]
|
||||
--,[Status] -- خالی
|
||||
--,[CreateID] -- خالی
|
||||
--,[CreateDate] --خالی
|
||||
--,[isDeleted] -- خالی
|
||||
--,[Abbr] -- بی اهمیت
|
||||
-- ,[ThirdPartIP] -- بی اهمیت
|
||||
FROM [mashruh].[dbo].[Commissions]
|
||||
|
||||
/**حوزه های انتخابی ***/
|
||||
SELECT [ID]
|
||||
,[Title]
|
||||
--,[ProvinceID] -- خالی
|
||||
FROM [mashruh].[dbo].[Howze]
|
||||
|
||||
-------------------------------------
|
||||
--[candid] -- فقط 583 مورد اسم نمایندگان --- مابقی ؟؟؟
|
||||
SELECT [candidId]
|
||||
,[candidName]
|
||||
,[candidLastname]
|
||||
--,[codeMelli] -- خالی
|
||||
--,[birthDate] -- خالی
|
||||
--,[deathDate] -- خالی
|
||||
--,[degree1] -- خالی
|
||||
--,[degree2] -- خالی
|
||||
--,[degree3] -- خالی
|
||||
--,[sessionname] -- شبه خالی
|
||||
FROM [mashruh].[dbo].[candid]
|
||||
|
||||
SELECT [candidHozeId]
|
||||
,l1.[candidId]
|
||||
,l2.candidName + ' - ' + l2.candidLastname as candid
|
||||
,l1.[hozeId]
|
||||
,l3.Title
|
||||
,[StartDate]
|
||||
,[endDate]
|
||||
,[dore]
|
||||
FROM [mashruh].[dbo].[candid_Hoze] l1
|
||||
left join candid l2 on l1.candidId=l2.candidId
|
||||
left join [Howze] l3 on l1.hozeId = l3.ID
|
||||
order by l1.hozeId, l1.candidId
|
||||
|
||||
--//******68 مورد فقط*****//
|
||||
SELECT [organizationId]
|
||||
,[organizationName]
|
||||
,[organizationAbbr]
|
||||
FROM [mashruh].[dbo].[organization]
|
||||
|
||||
/****** 196 مورد سمت ******/
|
||||
SELECT [sematId]
|
||||
,[sematName]
|
||||
FROM [mashruh].[dbo].[semat]
|
||||
|
||||
|
||||
/****** 14 مورد******/
|
||||
SELECT [subjectId]
|
||||
,[subjectText]
|
||||
,[subjectTableText]
|
||||
,[subjectClassName]
|
||||
FROM [mashruh].[dbo].[subject]
|
||||
---[subjectC] --???
|
||||
|
||||
/****** وزیرها ...مدعو جلسه ******/
|
||||
SELECT [ministerId]
|
||||
,[ministerName]
|
||||
,[ministerLastName]
|
||||
--,[ministerCodeMelli] -- خالی
|
||||
FROM [mashruh].[dbo].[minister]
|
||||
|
||||
/****** 5 مورد ******/
|
||||
SELECT [fileTypeId]
|
||||
,[fileTypeName]
|
||||
FROM [mashruh].[dbo].[fileType]
|
||||
|
||||
/****** Script for SelectTopNRows command from SSMS ******/
|
||||
/****** Script for SelectTopNRows command from SSMS ******/
|
||||
SELECT TOP (1000) [contentId]
|
||||
,[dasturId]
|
||||
,[text]
|
||||
--,[timeStart] --خالی
|
||||
--,[duration] -- 6 مورد کم اهمیت
|
||||
--,[timeInsert] -- زمان ورود به دیتابیس ... در سامانه جدید مهم نیست
|
||||
,[order]
|
||||
--,[label] -- خالی
|
||||
,[bossId]
|
||||
,[subjectCId]
|
||||
--,[subjectCNumber] -- ؟؟؟؟
|
||||
,[candidId]
|
||||
,[ministerId]
|
||||
,[organizationId]
|
||||
,[CommissionsId]
|
||||
,[sematId]
|
||||
--,[mpcode] --خالی
|
||||
--,[confirmed] --خالی
|
||||
--,[p3] -- مهم نیست !!!
|
||||
--,[p4] --خالی
|
||||
--,[timeInsert2] --خالی
|
||||
FROM [mashruh].[dbo].[content]
|
||||
where [timeInsert2] is not null
|
||||
|
||||
|
||||
/****** Script for SelectTopNRows command from SSMS ******/
|
||||
SELECT [sessionId]
|
||||
,[dore]
|
||||
,[ejlasieh]
|
||||
,[shomareJalaseh]
|
||||
,[timeStart]
|
||||
--,[bossStartId] -- ????
|
||||
,[timeEnd]
|
||||
--,[bossEndId] --???
|
||||
,[date]
|
||||
,[totalCount]
|
||||
,[SessionType]
|
||||
--,[abstract]
|
||||
--,[shamsiDate]
|
||||
--,[ghamariDate]
|
||||
-- ,[miladiDate]
|
||||
--,[confirmed]
|
||||
FROM [mashruh].[dbo].[session]
|
||||
order by dore,ejlasieh,shomareJalaseh
|
||||
|
||||
|
||||
SELECT [dasturId]
|
||||
,[dasturText]
|
||||
--,[timeStart] --خالی
|
||||
,[shomareDastur]
|
||||
,[sessionId]
|
||||
--,[duration] --خالی
|
||||
,[subjectId]
|
||||
--,[shomareh_shenaseh] -- 2 مورد
|
||||
--,[shomareh_Sabt] -- 1 مورد
|
||||
--,[p3] --خالی
|
||||
--,[p4] --خالی
|
||||
--,[confirmed] --خالی
|
||||
FROM [mashruh].[dbo].[dastur]
|
||||
|
||||
|
||||
|
||||
|
||||
--////////////////////////////////////////
|
||||
|
||||
SELECT
|
||||
l1.[contentId]
|
||||
--,[dasturId]
|
||||
,l2.[dasturText]
|
||||
,l2.[shomareDastur]
|
||||
,l2.[sessionId]
|
||||
|
||||
,l10.SessionType
|
||||
,l10.dore
|
||||
,l10.ejlasieh
|
||||
,l10.shomareJalaseh
|
||||
,l10.[date]
|
||||
,l10.timeStart
|
||||
,l10.timeEnd
|
||||
|
||||
,l3.[subjectText]
|
||||
,[text]
|
||||
,l4.[subjectCText]
|
||||
--,[timeStart] --خالی
|
||||
--,[duration] -- 6 مورد کم اهمیت
|
||||
--,[timeInsert] -- زمان ورود به دیتابیس ... در سامانه جدید مهم نیست
|
||||
,[order]
|
||||
--,[label] -- خالی
|
||||
,[bossId]
|
||||
--,[subjectCNumber] -- ؟؟؟؟
|
||||
,l1.candidId
|
||||
,l5.candidName + ' - ' + l5.candidLastname as candid
|
||||
,l6.ministerName + ' - ' + l6.ministerLastName as minister
|
||||
,l7.organizationName
|
||||
,l8.Title as Commissions
|
||||
--,l9.sematId
|
||||
,l9.[sematName]
|
||||
--,[mpcode] --خالی
|
||||
--,[confirmed] --خالی
|
||||
--,[p3] -- مهم نیست !!!
|
||||
--,[p4] --خالی
|
||||
--,[timeInsert2] --خالی
|
||||
FROM [mashruh].[dbo].[content] l1
|
||||
left join [dastur] l2 on l1.[dasturId] = l2.[dasturId]
|
||||
left join [subject] l3 on l2.[subjectId] = l3.subjectId
|
||||
left join [subjectC] l4 on l1.[subjectCId] = l4.subjectCId
|
||||
left join [candid] l5 on l1.candidId = l5.candidId
|
||||
left join minister l6 on l1.ministerId = l6.ministerId
|
||||
left join organization l7 on l1.[organizationId] = l7.organizationId
|
||||
left join [Commissions] l8 on l1.[CommissionsId] = l8.ID
|
||||
left join [semat] l9 on l1.sematId = l9.sematId
|
||||
left join [session] l10 on l2.[sessionId] = l10.sessionId
|
||||
order by l10.dore,l10.ejlasieh,l10.shomareJalaseh
|
||||
|
||||
|
||||
|
||||
/****** Script for SelectTopNRows command from SSMS ******/
|
||||
SELECT
|
||||
l1.[contentId]
|
||||
,l2.[dasturText]
|
||||
,l2.[shomareDastur]
|
||||
,l2.[sessionId]
|
||||
,l10.SessionType
|
||||
,l10.dore
|
||||
,l10.ejlasieh
|
||||
,l10.shomareJalaseh
|
||||
,l10.[date]
|
||||
,l10.timeStart
|
||||
,l10.timeEnd
|
||||
,l10.totalCount
|
||||
,l3.[subjectText]
|
||||
,[text]
|
||||
,l4.[subjectCText]
|
||||
,[order]
|
||||
,[bossId]
|
||||
,l1.candidId
|
||||
,l5.candidName + ' ' + l5.candidLastname as candid
|
||||
,l6.ministerName + ' ' + l6.ministerLastName as minister
|
||||
,l7.organizationName
|
||||
,l8.Title as Commissions
|
||||
,l9.[sematName]
|
||||
FROM [mashruh].[dbo].[content] l1
|
||||
left join [dastur] l2 on l1.[dasturId] = l2.[dasturId]
|
||||
left join [subject] l3 on l2.[subjectId] = l3.subjectId
|
||||
left join [subjectC] l4 on l1.[subjectCId] = l4.subjectCId
|
||||
left join [candid] l5 on l1.candidId = l5.candidId
|
||||
left join minister l6 on l1.ministerId = l6.ministerId
|
||||
left join organization l7 on l1.[organizationId] = l7.organizationId
|
||||
left join [Commissions] l8 on l1.[CommissionsId] = l8.ID
|
||||
left join [semat] l9 on l1.sematId = l9.sematId
|
||||
left join [session] l10 on l2.[sessionId] = l10.sessionId
|
||||
order by l10.dore,l10.ejlasieh,l10.shomareJalaseh,l2.[shomareDastur],l1.[order]
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/****** Script for SelectTopNRows command from SSMS ******/
|
||||
SELECT [F_LWSECTIONID], COUNT(*)
|
||||
FROM [AIPLawDCIT].[dbo].[lwsectionlog]
|
||||
group by [F_LWSECTIONID]
|
||||
order by COUNT(*) desc
|
||||
|
||||
|
||||
|
||||
SELECT F_LWLAWID, COUNT(*)
|
||||
FROM [AIPLawDCIT].[dbo].[lwreceiver]
|
||||
group by F_LWLAWID
|
||||
order by COUNT(*) desc
|
||||
|
||||
|
||||
SELECT [F_LWLAWID_EFFECTIVE], COUNT(*)
|
||||
FROM [AIPLawDCIT].[dbo].[lwlawchange]
|
||||
group by [F_LWLAWID_EFFECTIVE]
|
||||
order by COUNT(*) desc
|
||||
|
||||
SELECT [F_LWLAWID_EFFECTED], COUNT(*)
|
||||
FROM [AIPLawDCIT].[dbo].[lwlawchange]
|
||||
where [F_LWLAWID_EFFECTED] not in ( select id from lwlaw)
|
||||
group by [F_LWLAWID_EFFECTED]
|
||||
order by COUNT(*) desc
|
||||
|
||||
|
||||
select count(*) from lwlaw
|
||||
where id in ( select f_lwlawid from lwsection)
|
||||
or id in ( select f_lwlawid from lwlawtext)
|
||||
|
||||
|
||||
/****** Script for SelectTopNRows command from SSMS ******/
|
||||
SELECT [id]
|
||||
,[f_lwlawid]
|
||||
,[txt]
|
||||
,[f_lwphaseid]
|
||||
FROM [AIPLawDCIT].[dbo].[lwlawtext]
|
||||
where txt = '<html><body dir="rtl"></body></html>'
|
||||
|
||||
|
||||
/****** Script for SelectTopNRows command from SSMS ******/
|
||||
SELECT *
|
||||
FROM [AIPLawDCIT].[dbo].[lwsection]
|
||||
|
||||
SELECT F_LWLAWID, count(*)
|
||||
FROM [AIPLawDCIT].[dbo].[lwsection]
|
||||
group by F_LWLAWID
|
||||
order by count(*) desc
|
||||
|
||||
|
||||
/****** Script for SelectTopNRows command from SSMS ******/
|
||||
SELECT *
|
||||
FROM [AIPLawDCIT].[dbo].[lwlaw]
|
||||
where F_LWBASETABLEID_LAWTYPE = 4
|
||||
|
||||
|
||||
|
||||
SELECT f_lwlawtypeid, count(*)
|
||||
FROM [AIPLawDCIT].[dbo].[lwlaw]
|
||||
group by f_lwlawtypeid
|
||||
order by count(*) desc
|
||||
@@ -0,0 +1,53 @@
|
||||
/****** pahse*/
|
||||
|
||||
lwphase
|
||||
lwapprover
|
||||
lwexecutecondition
|
||||
|
||||
|
||||
|
||||
|
||||
[prdoc]
|
||||
opopinion
|
||||
opopiniongiver
|
||||
opopiniontopic
|
||||
prdoc
|
||||
from lwlaw l where [ISOPINION] = 1
|
||||
|
||||
|
||||
|
||||
lwsection
|
||||
lwlawstructure
|
||||
lwlawsectionstatus
|
||||
lwsectionchange
|
||||
Section_Type
|
||||
|
||||
lwsectionf
|
||||
lwsectiontopic
|
||||
lwsectionlog
|
||||
|
||||
|
||||
|
||||
|
||||
/************* خطای داده، عدم وجود ای دی هایش*/
|
||||
lwlawchange
|
||||
|
||||
LWLAWMAINNEXT /**تعداد بسیار کم 62 و مبهم*/
|
||||
lwlawproperty /*حدود 3 هزار و ظاهرا تکراری و کم ارزش چون در جدول lwlaw مطالبش هست*/
|
||||
lwlawpropertyLog/**تعداد بسیار کم 151 و مبهم*/
|
||||
|
||||
lwlawreapetedinfo /*داده ارزشمندی ندارد چون محتوای فیلدهایی که قرار است تکرار را مشخص کنند مثل هم هستند */
|
||||
where [reapetedIDs] != [rpids]
|
||||
|
||||
lwlawregulation /*داده ها درست وصل نیستند */
|
||||
SELECT l1.*,l2.CAPTION, l3.CAPTION
|
||||
FROM [AIPLawDCIT].[dbo].[lwlawregulation] l1
|
||||
left join lwlaw l2 on l1.F_LWLAWID_LAW=l2.id
|
||||
left join lwlaw l3 on l1.F_LWLAWID_REGULATION=l3.id
|
||||
|
||||
|
||||
lwlawtextErr/**تعداد بسیار کم 18 و مبهم*/
|
||||
|
||||
|
||||
/************** ??? */
|
||||
lwLawFlowType
|
||||
@@ -0,0 +1,14 @@
|
||||
select f_lwlawid, count(*)
|
||||
from lwlawtext
|
||||
group by f_lwlawid
|
||||
order by COUNT(*) desc
|
||||
|
||||
|
||||
select * from lwlaw
|
||||
where id not in
|
||||
(select f_lwlawid from lwlawtext)
|
||||
|
||||
|
||||
|
||||
select l1.*,lp.* from lwlawtext l1 left join lwphase lp on l1.f_lwphaseid=lp.id
|
||||
where l1.f_lwlawid = 2016487
|
||||
@@ -0,0 +1,3 @@
|
||||
select l1.*,lp.* from lwlawtext l1 left join lwphase lp on l1.f_lwphaseid=lp.id
|
||||
where l1.f_lwlawid = 115887
|
||||
order by lp.id
|
||||
@@ -0,0 +1,20 @@
|
||||
select co.CAPTION
|
||||
,count(*)
|
||||
from lwlaw l
|
||||
left join cmorganization co on l.[F_CMORGANIZATIONIDApprover]=co.id
|
||||
group by co.CAPTION
|
||||
order by count(*) desc
|
||||
|
||||
|
||||
|
||||
select co.CAPTION
|
||||
,count(*)
|
||||
from lwlawtext l1 left join lwlaw l on l1.f_lwlawid=l.id
|
||||
left join cmorganization co on l.[F_CMORGANIZATIONIDApprover]=co.id
|
||||
group by co.CAPTION
|
||||
order by count(*) desc
|
||||
|
||||
|
||||
|
||||
select * from lwlawtext
|
||||
where txt is not null
|
||||
@@ -0,0 +1,183 @@
|
||||
|
||||
SELECT [ID] as ref_id
|
||||
,[CAPTION] as title
|
||||
,[F_PARENTID] as parent_id
|
||||
,[THEHIERARCHY] as [order]
|
||||
--,[F_CMORGANIZATIONID_PREV]
|
||||
--,[F_CMORGANIZATIONID_NEXT]
|
||||
,[FROMDATE] as from_date
|
||||
--,[TODATE] as to_date
|
||||
,[F_CMBASETABLEID_ORGTYPE] as organ_type --{id:.., title:...}
|
||||
--,[F_RULBASETABLEID] -- مشخص نیست کجا وصل هست
|
||||
--,[OLDID]
|
||||
,[ISLAWAPPROVER] as is_law_aprover -- تایید کننده قانون
|
||||
,[ISLAWCOMMANDER] as is_law_commander -- دستور دهنده قانون
|
||||
,[ISREGULATIONAPPROVER] as is_regulation_aprover --تایید کننده مقرره
|
||||
,[ISREGULATIONCOMMANDER] as is_regulation_commander -- دستور دهنده مقرره
|
||||
,[ISLAWEXECUTOR] as is_law_executer -- مجری قانون
|
||||
,[ISLAWRECEIVER] as is_law_reciver -- گیرنده قانون
|
||||
,[ISREGULATIONEXECUTOR] as is_regulation_executer -- مجری مقرره
|
||||
,[ISREGULATIONRECEIVER] as is_regulation_reciver -- گیرنده مقرره
|
||||
--,[CODE]
|
||||
-- ,[ISACTIVE] ????
|
||||
--,[HISTORY] -- کم اهمیت
|
||||
,[ISPLANPROPOSER] -- پیشنهاد دهنده طرح
|
||||
,[ISPLANSIGNER] -- امضاء کننده طرح
|
||||
,[ISPLANOPINIONGIVER] -- نظر دهنده طرح
|
||||
,[ISPLANEDITPROPOSER] -- پیشنهاد دهنده ویرایش طرح
|
||||
,[ISGOVDELEGATE] -- نماینده دولت
|
||||
--,[OLDID_MAJLES]
|
||||
--,[OLDID_MAJLES_NAMAYANDEDOLAT]
|
||||
--,[OLDID_MAJLES_MARJAGHANOONGOZAR]
|
||||
--,[OLDID_MAJLES_PISHNAHAD]
|
||||
--,[OLDID_MAJLES_SIGNER]
|
||||
,[ISPLANCOMMANDER] -- دستور دهنده طرح
|
||||
--,[ISOPINIONGIVER] -- داده ندارد
|
||||
,[ISOPINIONRECEIVER] -- گیرنده نظر
|
||||
,[ISLETTERSENDERRECEIVER] -- گیرنده نامه
|
||||
,[ISPLANEXPERTREPORTSENDER] -- ارسال کننده گزارش کارشناس
|
||||
--,[OLDID_NAZAR_GIRANDENAZAR]
|
||||
--,[OLDID_LETTERSDRRCV_NAZAR]
|
||||
--,[ORGCOMMANDPREFIX] --داده ندارد
|
||||
FROM [AIPLawDCIT].[dbo].[cmorganization]
|
||||
order by parent_id
|
||||
--order by is_law_aprover desc, is_law_commander desc, organ_type, parent_id, title
|
||||
|
||||
|
||||
|
||||
select l.id as ref_id
|
||||
,l.CAPTION as title
|
||||
,isnull(t.caption,'') as type1
|
||||
-- ,t2.caption as type2
|
||||
,isnull(ls.caption,'') as state_etebar
|
||||
,isnull(lt.caption,'') as state_tanghih
|
||||
,isnull(co.CAPTION,'') as ts_ref
|
||||
,isnull([EXPIREDATE],'') as expire_date
|
||||
,isnull([majlesno],'') as majlesno
|
||||
,isnull(APPROVEDATE,'') as ts_date
|
||||
,isnull([APPROVEDATELast],'') as ts_date_last -- تعداد 11 مورد فقط اختلاف دارد
|
||||
,isnull((select top(1) txt from lwlawtext where f_lwlawid=l.id order by f_lwphaseid desc ),'') as content
|
||||
,(select STRING_AGG(F_CMORGANIZATIONID, ',') from [lwexecutor] where F_LWLAWID=l.id) as exceuter_CMORGANIZATION
|
||||
,(select STRING_AGG(F_CMORGANIZATIONID, ',') from [lwreceiver] where F_LWLAWID=l.id) as receiver_CMORGANIZATION
|
||||
--,(select top(10) STRING_AGG(F_TOPICID, ',') from [lwsectiontopic] where F_LWLAWID=l.id ) as topic_CMORGANIZATION
|
||||
from lwlaw l
|
||||
left join lwlawtype t on l.[f_lwlawtypeid]=t.id
|
||||
left join lwlawstatus ls on l.[f_lwlawstatusid] = ls.id
|
||||
left join lwlawtanghih lt on l.[f_lwlawtanghihid] = lt.id
|
||||
--left join lwlawtype t2 on l.[F_LWBASETABLEID_LAWTYPE]=t.id
|
||||
left join cmorganization co on l.[F_CMORGANIZATIONIDApprover]=co.id
|
||||
-- where l.CAPTION = '????? ???? ???? ????? ?????? ????? ??? ???? ????? ? ????? 4 ?????? ?? ????? ???? ????? ???? ????? ? ???? ? ???? ? ?? ? ???? ????? ????? ?????? ?????? ?????'
|
||||
--where majlesno is not null and co.CAPTION != 'مجلس شوراي اسلامي'
|
||||
|
||||
|
||||
|
||||
|
||||
SELECT l.[ID] as ref_id
|
||||
,l.SUBJECT as caption
|
||||
,l2.CAPTION as caption2
|
||||
,l.[OPINIONDATE] as opinion_date
|
||||
,[ARCHIVENO] as archive_no
|
||||
--,[F_CMBASETABLEID_CLASSIFICATION] -- کلا 8 و 1451 غیر نال ها داره و اون هم بی ارزش هست چون 8 یعنی «ندارد» و 1451 عادی
|
||||
,[F_OPOPINIONGIVERID] -- as ts_ref
|
||||
,[F_LWLAWID]
|
||||
,[DISTRIBUTENO] as rrk_no
|
||||
,[DISTRIBUTEDATE] as rrk_date
|
||||
,isnull((select top(1) DOCTEXT from prdoc where id=l.[F_PRDOCID] ),'') as content
|
||||
,(select STRING_AGG([F_LWTOPICID], ',') from [opopiniontopic] where [F_OPOPINIONID]=l.id) as topics
|
||||
--,[TOTALIMAGE] --مشخص نیست این برای چیست
|
||||
--این فیلدها، خالی بودند یا ارزشمند نبودند
|
||||
--,l.OPINIONLETTERNO,[REGISTRATIONNO],[F_OPOPINIONGIVERPERSONID],[ISELEMENTARY]
|
||||
--,[REALPERSONRECEIVE],[HASNOTE],[THECOMMENT],[OLDID]
|
||||
--,[ISBASEINFOCONFIRMED],[ISBASEDOCCONFIRMED],[ISTOPICCONFIRMED],[ISKEYWORDCONFIRMED],[ISHISTORYCONFIRMED],[DOSSIERCLASS]
|
||||
FROM [AIPLawDCIT].[dbo].[opopinion] l
|
||||
left join lwlaw l2 on l.F_LWLAWID=l2.id
|
||||
|
||||
|
||||
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
SELECT l1.[ID] as ref_id
|
||||
,[F_LWLAWID] as qanon_id
|
||||
,[F_LWPHASEID] as phase_id
|
||||
--,[CAPTION] -- تعداد 89 مورد بی ارزش
|
||||
,l1.[F_PARENTID] as parent_id
|
||||
,[TEXTORDER] as [order]
|
||||
,[SECTIONLEVEL] as level1
|
||||
,[FULLPATH]
|
||||
,[SECTIONTYPENOTEXT] -- بخش بندی متنی بخش مثل ب، چ، پ، ... -- البته خطای قابل توجه داره
|
||||
,[SECTIONTYPENO] -- شماره عدد موجود در بخش -- البته خطا داره
|
||||
--,[FIRSTSATENO] -- ??
|
||||
--,[LASTSTATENO] --??
|
||||
,[HIERARCHY]
|
||||
--,[STATENO] as number --؟؟؟؟؟
|
||||
,[F_CMBASETABLEID_SECTIONSTATUS] as qanon_type -- خطا دارد اعداد 12 تا 16 بی معنی هست،
|
||||
--,[F_LWLAWSTRUCTUREID] -- عمده فیلدهای این جدول اینجا موجود هست
|
||||
,[SECTIONTEXT] as content
|
||||
--,[OLDID]
|
||||
,[F_LWSECTIONID_REPLACED]
|
||||
---,[DISPLAYINCONTENTS] -- تعداد 147 مورد عدد 1 که معلوم نیست برای چیست!!!!
|
||||
--,[TMP]
|
||||
--,[F_LWLAWCHANGEID_FIRST] -- خطای جداول مرتبط
|
||||
--,[F_LWLAWCHANGEID_LAST] -- خطای جداول مرتبط
|
||||
,[ISINTERPRETATION] -- آیا تفسیری هست
|
||||
,l2.CAPTION as state_etebar --,[f_lwlawstatusid]
|
||||
,l3.CAPTION as state_tanghih --,[f_lwlawtanghihid]
|
||||
,[seclen]
|
||||
--,[hr] -- تکرار [HIERARCHY]
|
||||
--,[desc1] --22 مورد داده بی ارزش
|
||||
--,[f_sourcetypeid] --22 مورد داده بی ارزش
|
||||
--,[sourceid] --22 مورد داده بی ارزش
|
||||
--,[sourceurl] -- خالی
|
||||
--,[F_LWLAWCHANGEID] -- خرابی جدول مرتبط [F_LWLAWCHANGEID]
|
||||
,(select STRING_AGG([F_TOPICID], ',') from [lwsectiontopic] where [F_SECTIONID]=l1.id) as topics
|
||||
,l4.CAPTION as qanon_title
|
||||
,isnull(co.CAPTION,'') as ts_ref
|
||||
,isnull(l4.[EXPIREDATE],'') as expire_date
|
||||
,isnull(l4.APPROVEDATE,'') as ts_date
|
||||
,isnull(l4.[APPROVEDATELast],'') as ts_date_last
|
||||
|
||||
FROM [AIPLawDCIT].[dbo].[lwsection] l1
|
||||
left join lwlawstatus l2 on l1.f_lwlawstatusid=l2.id
|
||||
left join lwlawtanghih l3 on l1.[f_lwlawtanghihid]=l3.id
|
||||
left join lwlaw l4 on l1.F_LWLAWID = l4.id
|
||||
left join cmorganization co on l4.[F_CMORGANIZATIONIDApprover]=co.id
|
||||
where [SECTIONTEXT] = ''
|
||||
|
||||
|
||||
-- where [F_LWSECTIONID_REPLACED] is not null and [F_LWSECTIONID_REPLACED] !=0
|
||||
--where [ISINTERPRETATION] is not null and [ISINTERPRETATION] !=0
|
||||
--where LASTSTATENO != 0
|
||||
order by qanon_id,parent_id, [order]
|
||||
|
||||
|
||||
--/////////////////////////////////////////////////////
|
||||
-- [lwsection].[F_LWSECTIONID_REPLACED]
|
||||
-- مواردی که باعث تغییرات بخش قانون شده است
|
||||
|
||||
SELECT l1.[ID] as F_LWSECTIONID1
|
||||
,l1.[F_LWLAWID] as F_LWLAWID1
|
||||
,l1.F_LWPHASEID as F_LWPHASEID1
|
||||
--,l1.[SECTIONTEXT] as content1
|
||||
,l1.[F_LWSECTIONID_REPLACED] as F_LWSECTIONID2
|
||||
--,l1.[F_LWLAWCHANGEID]
|
||||
--,l1.seclen
|
||||
--,l2.[F_LWLAWID] -- = l1.[F_LWLAWID]
|
||||
--,l2.[SECTIONTEXT]
|
||||
--,l2.[F_LWLAWCHANGEID]
|
||||
--,l2.seclen
|
||||
,l3.SECTIONTEXT -- متن اگر داشت کامل تر از متن خود بخش جاگذاری شده است، خوبه بروز رسانی بشود
|
||||
--,l3.* -- داده تکراری بود
|
||||
,l4.F_LWLAWID_EFFECTIVE as F_LWLAWID2 -- قانونی که باعث تغییر شده است
|
||||
,l4.F_LWPHASEID_EFFECTIVE as F_LWPHASEID2
|
||||
--,l5.* -- داده تکراری بود و ارزشمند نداشت
|
||||
--,l6.* -- در جای خودش اطلاعاتش اضافه باید شود
|
||||
--,l7.* -- تکرار داده l6 هست
|
||||
FROM [AIPLawDCIT].[dbo].[lwsection] l1
|
||||
left join [AIPLawDCIT].[dbo].[lwsection] l2 on l1.F_LWSECTIONID_REPLACED = l2.id
|
||||
left join lwsectionlog l3 on l1.id=l3.F_LWSECTIONID
|
||||
left join lwlawchange l4 on l1.[F_LWLAWCHANGEID]=l4.id
|
||||
--left join lwlawchange l5 on l2.[F_LWLAWCHANGEID]=l5.id
|
||||
left join lwphase l6 on l4.F_LWLAWID_EFFECTIVE = l6.id
|
||||
--left join lwphase l7 on l4.F_LWLAWID_EFFECTIVE = l7.id
|
||||
where l1.[F_LWSECTIONID_REPLACED] is not null
|
||||
order by l1.F_LWLAWID
|
||||
@@ -0,0 +1,38 @@
|
||||
/****** Script for SelectTopNRows command from SSMS ******/
|
||||
SELECT
|
||||
l1.[contentId]
|
||||
,l2.[dasturText]
|
||||
,l2.[shomareDastur]
|
||||
,l2.[sessionId]
|
||||
,l10.SessionType
|
||||
,l10.dore
|
||||
,l10.ejlasieh
|
||||
,l10.shomareJalaseh
|
||||
,l10.[date]
|
||||
,l10.timeStart
|
||||
,l10.timeEnd
|
||||
,l10.totalCount
|
||||
,l3.[subjectText]
|
||||
,[text]
|
||||
,l4.[subjectCText]
|
||||
,[order]
|
||||
,[bossId]
|
||||
,l1.candidId
|
||||
,l5.candidName + ' ' + l5.candidLastname as candid
|
||||
,l6.ministerName + ' ' + l6.ministerLastName as minister
|
||||
,l7.organizationName
|
||||
,l8.Title as Commissions
|
||||
,l9.[sematName]
|
||||
FROM [mashruh].[dbo].[content] l1
|
||||
left join [dastur] l2 on l1.[dasturId] = l2.[dasturId]
|
||||
left join [subject] l3 on l2.[subjectId] = l3.subjectId
|
||||
left join [subjectC] l4 on l1.[subjectCId] = l4.subjectCId
|
||||
left join [candid] l5 on l1.candidId = l5.candidId
|
||||
left join minister l6 on l1.ministerId = l6.ministerId
|
||||
left join organization l7 on l1.[organizationId] = l7.organizationId
|
||||
left join [Commissions] l8 on l1.[CommissionsId] = l8.ID
|
||||
left join [semat] l9 on l1.sematId = l9.sematId
|
||||
left join [session] l10 on l2.[sessionId] = l10.sessionId
|
||||
order by l10.dore,l10.ejlasieh,l10.shomareJalaseh,l2.[shomareDastur],l1.[order]
|
||||
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
--select count(*) from lwLaw
|
||||
--select count(*) from lwSection
|
||||
select * from lwLaw
|
||||
where [F_LWBASETABLEID_LAWTYPE] is null
|
||||
|
||||
|
||||
select F_LWLAWID, count(*) from [lwPhase]
|
||||
group by F_LWLAWID
|
||||
order by count(*) desc
|
||||
|
||||
|
||||
select F_LWLAWID, count(*) from [lwPhase]
|
||||
group by F_LWLAWID
|
||||
order by count(*) desc
|
||||
|
||||
|
||||
|
||||
SELECT top(1000) *
|
||||
FROM [Qavanin].[dbo].[lwLaw]
|
||||
where ISLAW=1
|
||||
order by APPROVEDATE desc
|
||||
|
||||
|
||||
|
||||
|
||||
-- محتوای قوانین و مقرراتی که وجود ندارد
|
||||
SELECT *
|
||||
FROM [Qavanin].[dbo].[lwLaw]
|
||||
where id in (select f_lwlawid from lwphase where len(LawText)<8)
|
||||
|
||||
|
||||
-- محتوای قوانین که وجود ندارد
|
||||
SELECT *
|
||||
FROM [Qavanin].[dbo].[lwLaw]
|
||||
where id in (select f_lwlawid from lwphase where len(LawText)<8)
|
||||
and ISLAW =1
|
||||
|
||||
|
||||
|
||||
|
||||
-- دسته بندی تعداد قوانین و مقررات
|
||||
select l2.caption,[F_LWBASETABLEID_LAWTYPE], count(*) from lwlaw l1
|
||||
left join cmBasetable l2 on l1.[F_LWBASETABLEID_LAWTYPE]=l2.id
|
||||
group by l2.caption,[F_LWBASETABLEID_LAWTYPE]
|
||||
order by [F_LWBASETABLEID_LAWTYPE]
|
||||
|
||||
|
||||
-- تعداد قوانین
|
||||
select count(*) from lwlaw l1 where ISLAW = 1
|
||||
|
||||
|
||||
-- رای و نظرها
|
||||
select l2.CAPTION, l1.* from opOpinion l1
|
||||
left join opOpiniongiver l2 on l1.F_OPOPINIONGIVERID=l2.id
|
||||
|
||||
-- دسته بندی رای و نظرها
|
||||
select l2.CAPTION, count(*) from opOpinion l1
|
||||
left join opOpiniongiver l2 on l1.F_OPOPINIONGIVERID=l2.id
|
||||
group by l2.CAPTION
|
||||
|
||||
|
||||
--select * from lwlaw where id = 83695
|
||||
--select * from [lwPhase] where F_LWLAWID = 83695
|
||||
|
||||
SELECT F_LWLAWID, count(*)
|
||||
FROM [Qavanin].[dbo].[lwSection]
|
||||
where F_LWLAWID in (select id from lwLaw where ISLAW=1)
|
||||
group by F_LWLAWID
|
||||
order by count(*) desc
|
||||
|
||||
|
||||
|
||||
|
||||
SELECT count(*)
|
||||
FROM [Qavanin].[dbo].[lwSection]
|
||||
where F_LWLAWID in (select id from lwLaw where ISREGULATION=1)
|
||||
|
||||
|
||||
SELECT * FROM [Qavanin].[dbo].[opOpinion]
|
||||
where F_PRDOCID is NULL
|
||||
|
||||
|
||||
|
||||
|
||||
select l.id as ref_id,l.CAPTION as title
|
||||
--,isnull(t.caption,'') as rule_type
|
||||
--,isnull(ls.caption,'') as state_etebar
|
||||
--,isnull(lt.caption,'') as state_tanghih
|
||||
,isnull(co.CAPTION,'') as ts_ref
|
||||
,isnull([EXPIREDATE],'') as expire_date
|
||||
--,isnull([majlesno],'') as majlesno
|
||||
,isnull(APPROVEDATE,'') as ts_date
|
||||
--,isnull([APPROVEDATELast],'') as ts_date_last
|
||||
--,isnull((select top(1) txt from lwlawtext where f_lwlawid=l.id order by f_lwphaseid desc ),'') as content
|
||||
,(select STRING_AGG(F_CMORGANIZATIONID, ',') from [lwexecutor] where F_LWLAWID=l.id) as exceuter_CMORGANIZATION
|
||||
,(select STRING_AGG(F_CMORGANIZATIONID, ',') from [lwreceiver] where F_LWLAWID=l.id) as receiver_CMORGANIZATION
|
||||
from lwlaw l
|
||||
--left join lwlawtype t on l.[f_lwlawtypeid]=t.id
|
||||
--left join lwlawstatus ls on l.[f_lwlawstatusid] = ls.id
|
||||
--left join lwlawtanghih lt on l.[f_lwlawtanghihid] = lt.id
|
||||
left join cmorganization co on l.[F_CMORGANIZATIONIDApprover]=co.id
|
||||
|
||||
|
||||
|
||||
select
|
||||
s.ID as sectionId
|
||||
,isnull(s.CAPTION,'') as title -- عنوان بخش: مثلا ماده 5
|
||||
,isnull(s.F_PARENTID,0) as parentId
|
||||
,isnull(lss.CAPTION,'') as sectionStatus -- lwLawSectionStatus_table: ... منسوخه، معتبر، اصلاحی، موقت و
|
||||
,isnull(s.SECTIONTEXT,'') as sectionText -- متن ماده یا تبصره
|
||||
,isnull(s.SECTIONLEVEL,0) as sectionLevel -- نسبت به عنوان قانون نامرتب و دارای مقدار تکراری هم هست ؟؟؟
|
||||
,isnull(nestedLawType.CAPTION,'') as lawType
|
||||
,isnull(nestedLawStatus.CAPTION,'') as lawStatus
|
||||
,isnull(s.TEXTORDER,0) as textOrder -- ترتیب نمایش مواد و تبصره ها
|
||||
,s.STATENO as stateNo -- ???
|
||||
,isnull(s.SECTIONTYPENO,0) as sectionTypeNumber -- دوهزار رکورد با مقدار صفر دارد اما مقادیر دیگری نیز پذیرفته است ؟؟؟
|
||||
-- بیش از پنج هزار رکورد با مقدار بالاتر از 1500 دارد که چنین مقادیری در جدول سکشن_تایپ وجود ندارد پس با این جدول رابطه ندارد
|
||||
,isnull(l.CAPTION,'') as lawTitle -- عنوان قانون
|
||||
,isnull(l.ID,0) as lawId -- شناسه قانون
|
||||
,isnull(l.APPROVEDATE,'') as aproveDate -- تاریخ تصویب
|
||||
,isnull(l.EXPIREDATE,'') as expireDate -- تاریخ انقضا
|
||||
,isnull(s.F_LWPHASEID,0) as phaseId -- شناسه فاز
|
||||
,s.FULLPATH as sectionFullPath -- عنوان ماده یا تبصره
|
||||
,isnull(s.SECTIONTYPENOTEXT,'') as sectionType -- ??? استفساریه، کنوانسیون، موافقت نامه، اساسنامه، تفسیر، دوم ، سوم ، چهارم، دوازدهم، خالی، 1، 2، 3، 4
|
||||
,isnull(s.FIRSTSATENO,0) as firstStateNo -- ??? بازه 0 تا 169
|
||||
,isnull(s.LASTSTATENO,0) as lastStateNo -- ??? بازه 0 تا 112
|
||||
,isnull(s.HIERARCHY,'') as hierarchy
|
||||
,isnull(s.DISPLAYINCONTENTS,0) as displayInContents -- ??? صد و پنجاه و سه رکورد دارای مقدار یک و بقیه یک میلیون رکورد مقدار 0 دارد
|
||||
,isnull(s.ISINTERPRETATION,0) as isInterpretation -- ??? چهارصد و پنجاه و سه رکورد با مقدار یک دارد و بقیه مقادیر نال است
|
||||
,isnull(nestedLawApprover.CAPTION,'') as ts_ref -- مرجع تصویب
|
||||
,(SELECT STRING_AGG(CONVERT(NVARCHAR(max),F_TOPICID), ',') WITHIN GROUP (ORDER BY ID) AS AggregatedResult FROM lwsectiontopic where [F_SECTIONID]=s.id) as topics
|
||||
,l.[ISLAW] -- قانون
|
||||
,l.[ISREGULATION] -- مقرره
|
||||
--,l.[ISOPINION] -- نظر و رای -- چون نظر ور رای جزء نگاری نشدند لذا هیچگاه 1 نمی شود
|
||||
,l.[ISCORRECTIONLETTER] -- اصلاحیه
|
||||
--,nestedRegulationType.CAPTION as regulation_type
|
||||
,(
|
||||
SELECT top (1) p3.CAPTION
|
||||
FROM [lwPhase] p1
|
||||
left join [lwApprover] p2 on p1.ID=p2.F_LWPHASEID
|
||||
left join cmOrganization p3 on p2.F_CMORGANIZATIONID = p3.id
|
||||
where l.ID = p1.F_LWLAWID
|
||||
order by p2.APPROVEDATE asc
|
||||
) as regulationType
|
||||
|
||||
from lwSection s
|
||||
left join lwLawSectionStatus lss on s.F_CMBASETABLEID_SECTIONSTATUS = lss.ID
|
||||
left join lwLaw l on s.F_LWLAWID = l.ID
|
||||
left JOIN (
|
||||
SELECT l2.F_LWBASETABLEID_LAWTYPE,l2.ID,cbt.CAPTION
|
||||
FROM lwLaw l2
|
||||
left JOIN cmBasetable cbt ON l2.F_LWBASETABLEID_LAWTYPE = cbt.ID
|
||||
) AS nestedLawType ON s.F_LWLAWID = nestedLawType.ID
|
||||
left JOIN (
|
||||
SELECT l2.[F_LWBASETABLEID_REGULATIONTYPE],l2.ID,cbt.CAPTION
|
||||
FROM lwLaw l2
|
||||
left JOIN cmBasetable cbt ON l2.[F_LWBASETABLEID_REGULATIONTYPE] = cbt.ID
|
||||
) AS nestedRegulationType ON s.F_LWLAWID = nestedRegulationType.ID
|
||||
left JOIN (
|
||||
SELECT
|
||||
p3.CAPTION
|
||||
,p1.F_LWLAWID
|
||||
FROM [lwPhase] p1
|
||||
left join [lwApprover] p2 on p1.ID=p2.F_LWPHASEID
|
||||
left join cmOrganization p3 on p2.F_CMORGANIZATIONID = p3.id
|
||||
|
||||
) AS nestedLawApprover ON s.F_LWLAWID = nestedLawApprover.F_LWLAWID
|
||||
|
||||
left JOIN (
|
||||
SELECT l3.F_CMBASETABLEID_LASTSTATUS,l3.ID,lss2.CAPTION
|
||||
FROM lwLaw l3
|
||||
left JOIN lwLawSectionStatus lss2 ON l3.F_LWBASETABLEID_LAWTYPE = lss2.ID
|
||||
) AS nestedLawStatus ON s.F_LWLAWID = nestedLawStatus.ID
|
||||
where l.[ISLAW] = 1
|
||||
order by s.F_LWLAWID,textOrder
|
||||
@@ -0,0 +1,46 @@
|
||||
import pyodbc
|
||||
|
||||
# region constant values
|
||||
# این توکن بسیار مهم است. چون هر از گاهی این توکن منقضی می شود
|
||||
# و باید توکن معتبر جدید از سایت قوانین درحالت لاگین شده،
|
||||
# دریافت شود و به جای توکن زیر جایگزین شود
|
||||
TOKEN = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3MjU5ODAwODQsImp0aSI6IllWR2N3V2UrTGltTVFhbVwvS0wrd1NvVDRlVk1ZdjhaYSIsImlzcyI6bnVsbCwiZXhwIjoxNzI3MjgwMDgzLCJhdWQiOm51bGwsImRhdGEiOnsiaWQiOjIsImZpcnN0X25hbWUiOiJcdTA2MmRcdTA2NDVcdTA2Y2NcdTA2MmYiLCJsYXN0X25hbWUiOiJcdTA2MzVcdTA2NDFcdTA2MjdcdTA2Y2NcdTA2Y2MiLCJlbWFpbCI6InNhZmFlaS5oYW1pZEBnbWFpbC5jb20iLCJ1c2VybmFtZSI6ImhzYWZhZWkiLCJ1c2VyX2xldmVsIjoyfX0.bKLh7J_PYpcTy9sZ1VqMF0Vd2GvCHNXWX130ny8WZRY'
|
||||
ACCEPT = "application/json"
|
||||
HEADERS = {"Authorization": TOKEN, "Accept": ACCEPT}
|
||||
|
||||
# BASE_URL = "https://api.tavasi.ir/"
|
||||
BASE_URL = "http://192.168.23.160:8080/"
|
||||
|
||||
# endregion
|
||||
|
||||
def create_cursor(dbname = ''):
|
||||
if dbname == '':
|
||||
dbname = "Qavanin"
|
||||
|
||||
server = "DESKTOP-ENVCI85"
|
||||
database = dbname
|
||||
username = "Mofid3"
|
||||
password = "hs110saf"
|
||||
|
||||
# ******** مهم *********
|
||||
# uncomment for jokar pc
|
||||
# server = "MOFID5"
|
||||
# database = dbname
|
||||
# username = "Mofid5"
|
||||
# password = "12345"
|
||||
|
||||
# ENCRYPT defaults to yes starting in ODBC Driver SQL Server. It's good to always specify ENCRYPT=yes on the client side to avoid MITM attacks.
|
||||
cnxn = pyodbc.connect(
|
||||
"DRIVER={SQL Server};SERVER="
|
||||
+ server
|
||||
+ ";DATABASE="
|
||||
+ database
|
||||
+ ";Trusted_Connection=yes;UID="
|
||||
+ username
|
||||
+ ";PWD="
|
||||
+ password
|
||||
)
|
||||
# cnxn = pyodbc.connect('DSN=sqldsn;')
|
||||
cursor = cnxn.cursor()
|
||||
return cursor, cnxn
|
||||
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
import pickle
|
||||
import re
|
||||
import string
|
||||
import os
|
||||
|
||||
|
||||
class DataHelper():
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def clean_text(self, text_doc, new_line_elimination):
|
||||
punctuations = r')(}{:؟!،؛»«.' + r"/<>?.,:;"
|
||||
punctuations = '[' + punctuations + string.punctuation + ']'
|
||||
punctuations = punctuations.replace("@", "")
|
||||
|
||||
text_doc.strip()
|
||||
|
||||
# pattern = ur'\s*@[a-zA-Z0-9]*\s*'
|
||||
# tmp = re.findall(pattern, text_doc)
|
||||
# newstring = re.sub(pattern, eliminate_pattern, text_doc)
|
||||
|
||||
|
||||
#finding the numbers
|
||||
pattern = r"[-+]?\d*\.\d+|\d+"
|
||||
nums_list = re.findall(pattern, text_doc)
|
||||
newstring = re.sub(pattern, 'floatingpointnumber', text_doc)
|
||||
|
||||
|
||||
#pattern = '\s*' + punctuations + '+' + '\s*'
|
||||
#tmp = re.findall(pattern, newstring)
|
||||
#newstring = re.sub(pattern, self.add_space, newstring)
|
||||
|
||||
# pattern = u'([a-zA-Z0-9]+)(\s*)(' + punctuations + u')(\s*)([a-zA-Z0-9]+)'
|
||||
# rep = ur'\1\3\5'
|
||||
# tmp = re.findall(pattern, newstring)
|
||||
# newstring = re.sub(pattern, rep, newstring)
|
||||
|
||||
pattern = r'[\n]+'
|
||||
tmp = re.findall(pattern, newstring)
|
||||
if new_line_elimination:
|
||||
newstring = re.sub(pattern, " ", newstring)
|
||||
else:
|
||||
# newstring = re.sub(pattern, "\n", newstring)
|
||||
pass
|
||||
|
||||
punctuations = r")(}{:؟!-،؛»«.@$&%" + r"/<>?.,:;"
|
||||
latinLettersDigits = r"a-zA-Z0-9"
|
||||
pattern = r'[^' + punctuations + latinLettersDigits + 'آ-ی' + '' + '\d\s:]'
|
||||
tmp = re.findall(pattern, newstring)
|
||||
newstring = re.sub(pattern, self.eliminate_pattern, newstring)
|
||||
|
||||
pattern = r'[ ]+'
|
||||
tmp = re.findall(pattern, newstring)
|
||||
newstring = re.sub(pattern, ' ', newstring)
|
||||
|
||||
for number in nums_list:
|
||||
pattern = 'floatingpointnumber'
|
||||
newstring = re.sub(pattern, number, newstring, 1)
|
||||
|
||||
return newstring
|
||||
|
||||
def add_space(self, mystring):
|
||||
mystring = mystring.group() # this method return the string matched by re
|
||||
mystring = mystring.strip(' ') # ommiting the whitespace around the pucntuation
|
||||
mystring = " " + mystring + " " # adding a space after and before punctuation
|
||||
return mystring
|
||||
|
||||
def replace_newline_with_dot(self, mystring):
|
||||
return ' . '
|
||||
|
||||
def eliminate_pattern(self, mystring):
|
||||
return ""
|
||||
|
||||
def load_var(self, load_path):
|
||||
file = open(load_path, 'rb')
|
||||
variable = pickle.load(file)
|
||||
file.close()
|
||||
return variable
|
||||
|
||||
def save_var(self, save_path, variable):
|
||||
print("saving vars ...")
|
||||
file = open(save_path, 'wb')
|
||||
pickle.dump(variable, file)
|
||||
print("variable saved.")
|
||||
file.close()
|
||||
|
||||
def build_stem_dictionary(self, normalizer, verb_tense_path, mokasar_noun_path):
|
||||
path_dir = "resource/Persian_Dependency_Treebank/Data/2ndRep"
|
||||
lexicon_stem = set()
|
||||
verb_stem = set()
|
||||
#verb_tense_map = {}
|
||||
verb_p2f_map = {}
|
||||
verb_f2p_map = {}
|
||||
for fileName in os.listdir(path_dir):
|
||||
file_path = path_dir + "/" + fileName
|
||||
with open(file_path, "r") as input:
|
||||
input_content = input.readlines()
|
||||
for el in input_content:
|
||||
el = normalizer.sub_alphabets(el)
|
||||
el = el.split("\t")
|
||||
if (len(el) > 2):
|
||||
if (el[3] == 'V'):
|
||||
tmp_pos = "V"
|
||||
else:
|
||||
tmp_pos = "N"
|
||||
stem_word = el[2]
|
||||
stem_word = stem_word.split("#")
|
||||
stem_word = [x.strip('\u200c') for x in stem_word]
|
||||
if (tmp_pos == "V" and len(stem_word) == 2):
|
||||
if (len(stem_word[0]) != 0 and len(stem_word[1]) != 0):
|
||||
verb_p2f_map[stem_word[0]] = stem_word[1]
|
||||
verb_f2p_map[stem_word[1]] = stem_word[0]
|
||||
verb_stem.add(stem_word[0])
|
||||
verb_stem.add(stem_word[1])
|
||||
if(tmp_pos == 'V' and len(stem_word) == 3):
|
||||
if(len(stem_word[0]) != 0 and len(stem_word[1]) != 0 and len(stem_word[2]) !=0):
|
||||
#verb_prifix.add(stem_word[0])
|
||||
verb_p2f_map[stem_word[1]] = stem_word[2]
|
||||
verb_f2p_map[stem_word[2]] = stem_word[1]
|
||||
verb_stem.add(stem_word[1])
|
||||
verb_stem.add(stem_word[2])
|
||||
for t in stem_word:
|
||||
if len(t) > 1:
|
||||
if (tmp_pos == 'N'):
|
||||
lexicon_stem.add(t)
|
||||
|
||||
with open(verb_tense_path, "r") as bon_file:
|
||||
bon_file_content = bon_file.readlines()
|
||||
for el in bon_file_content:
|
||||
el = el.strip()
|
||||
el = normalizer.sub_alphabets(el)
|
||||
el = el.split()
|
||||
el = [x.strip('\u200c') for x in el]
|
||||
|
||||
verb_p2f_map[el[0]] = el[1]
|
||||
verb_f2p_map[el[1]] = el[0]
|
||||
verb_stem.add(el[0])
|
||||
verb_stem.add(el[1])
|
||||
|
||||
irregular_noun = {}
|
||||
with open(mokasar_noun_path, "r") as input:
|
||||
input_content = input.readlines()
|
||||
for el in input_content:
|
||||
el = normalizer.sub_alphabets(el)
|
||||
el = el.replace("\t\t", "\t")
|
||||
el = el.strip().split("\t")
|
||||
el = [x.strip('\u200c') for x in el]
|
||||
irregular_noun[el[0]] = el[1]
|
||||
lexicon_stem.add(el[0])
|
||||
|
||||
verb_tense_map = [verb_p2f_map, verb_f2p_map]
|
||||
return lexicon_stem, verb_stem, verb_tense_map, irregular_noun
|
||||
@@ -0,0 +1,863 @@
|
||||
from normalizer import Normalizer
|
||||
from tokenizer import *
|
||||
import jalali
|
||||
import re
|
||||
from re import sub
|
||||
import textwrap
|
||||
from html import escape
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
# from lxml import etree
|
||||
import datetime
|
||||
#enumerate(token_list):
|
||||
_normalizer = Normalizer(date_normalizing_needed=True)
|
||||
|
||||
yeAr = r"ﻱ|ې|ێ|ے|ى|ي|ئ"
|
||||
yeFr= r"ی"
|
||||
keAr = r"ڭ|ﻚ|ﮎ|ﻜ|ﮏ|ګ|ﻛ|ﮑ|ﮐ|ڪ|ك"
|
||||
keFr = r"ک"
|
||||
mark1 = r'#\[#'
|
||||
mark2 = r'#\]#'
|
||||
hTag1 = r'<'
|
||||
hTag2 = r'>'
|
||||
tableTag=["table","tr", "th", "td", "TABLE", "TR", "TH", "TD"]
|
||||
strTable = ''
|
||||
for tag in tableTag:
|
||||
if strTable != '':
|
||||
strTable += '|'
|
||||
strTable += '('+tag+')'
|
||||
regTable = r'<(?P<slash>\/)*(?P<tag>'+strTable+')(?P<class>[^>]+)*>'
|
||||
regTableReplace = r'#[#\g<slash>\g<tag>\g<class>#]#'
|
||||
|
||||
|
||||
def isNeedHtml(html):
|
||||
if "<TABLE" in html or "<table" in html or "</TR" in html or "</tr" in html :
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def removeHtmlTags(html, exeptionTag=[]):
|
||||
#reg1 = r'<[^>]+>'
|
||||
|
||||
if exeptionTag.__len__ :
|
||||
exceptTags = ''
|
||||
for tag in exeptionTag:
|
||||
if exceptTags != '':
|
||||
exceptTags += '|'
|
||||
exceptTags += '('+tag+')'
|
||||
reg1 = r'<(?P<slash>/)*(?P<tag>'+exceptTags+')(?P<class>[^>]+)*>'
|
||||
html = sub(reg1, regTableReplace, html)
|
||||
|
||||
|
||||
soup = BeautifulSoup(html, "html.parser")
|
||||
text = soup.get_text("\n", strip=True)
|
||||
|
||||
if exeptionTag.__len__ :
|
||||
text = sub(mark1, hTag1, text)
|
||||
text = sub(mark2, hTag2, text)
|
||||
|
||||
return text
|
||||
|
||||
|
||||
def removeHtmlNoTableTag(html):
|
||||
|
||||
# خطا داره و هنگ می کنه در test2.py
|
||||
html = sub(regTable, regTableReplace, html)
|
||||
soup = BeautifulSoup(html, "html.parser")
|
||||
text = soup.get_text("\n", strip=True)
|
||||
|
||||
text = sub(mark1, hTag1, text)
|
||||
text = sub(mark2, hTag2, text)
|
||||
|
||||
return text
|
||||
|
||||
def normalizerData(data):
|
||||
global _normalizer
|
||||
normalTitle, dates = _normalizer.normalize(data, return_dates=True)
|
||||
tdates = []
|
||||
for d in dates:
|
||||
if not d.startswith("num"):
|
||||
try:
|
||||
tsd = jdate2timestamp(d)
|
||||
cdate = d
|
||||
except:
|
||||
try:
|
||||
d = d.replace("y", "")
|
||||
d = d.replace("m", "/")
|
||||
d = d.replace("d", "/")
|
||||
m = re.match(r"^(\d{4})\D(\d{1,2})\D(\d{1,2})$", d)
|
||||
if m:
|
||||
[year, month, day] = [
|
||||
int(m.group(1)),
|
||||
int(m.group(2)),
|
||||
int(m.group(3)),
|
||||
]
|
||||
if year > 1200 and year < 1550:
|
||||
if month < 1 or month > 12:
|
||||
month = 1
|
||||
if day < 1 or day > 31:
|
||||
day = 1
|
||||
cdate = str(year) + "/" + str(month) + "/" + str(day)
|
||||
tsd = jdate2timestamp(cdate)
|
||||
else:
|
||||
# cdate = "1403/03/03"
|
||||
# tsd = jdate2timestamp(cdate)
|
||||
continue
|
||||
else:
|
||||
# cdate = "1403/03/03"
|
||||
# tsd = jdate2timestamp(cdate)
|
||||
continue
|
||||
except:
|
||||
# print("Error in:"+ d +" for id: " + id)
|
||||
# cdate = "1403/03/03"
|
||||
# tsd = jdate2timestamp(cdate)
|
||||
continue
|
||||
tdates.append({"date": cdate, "timestamp": tsd, "index": 0, "slice": ""})
|
||||
|
||||
return normalTitle,tdates
|
||||
|
||||
def normalizerDate2(inputString):
|
||||
global _normalizer
|
||||
normalizedString, dates, recognized_dates, recognized_numbers = _normalizer.normalize(inputString, return_dates=True)
|
||||
tdates = []
|
||||
for date_item in recognized_dates:
|
||||
date_part = date_item['date']
|
||||
date_token_index = date_item['date_token_index']
|
||||
start_date_token_index = date_item['start_date_token_index']
|
||||
end_date_token_index = date_item['end_date_token_index']
|
||||
if not date_part.startswith("num"):
|
||||
try:
|
||||
cdate = date_part
|
||||
tsd = jdate2timestamp(date_part)
|
||||
except:
|
||||
try:
|
||||
date_part = date_part.replace("y", "")
|
||||
date_part = date_part.replace("m", "/")
|
||||
date_part = date_part.replace("d", "/")
|
||||
m = re.match(r"^(\d{4})\D(\d{1,2})\D(\d{1,2})$", date_part)
|
||||
if m:
|
||||
[year, month, day] = [
|
||||
int(m.group(1)),
|
||||
int(m.group(2)),
|
||||
int(m.group(3)),
|
||||
]
|
||||
if year > 1200 and year < 1550:
|
||||
if month < 1 or month > 12:
|
||||
month = 1
|
||||
if day < 1 or day > 31:
|
||||
day = 1
|
||||
cdate = str(year) + "/" + str(month) + "/" + str(day)
|
||||
tsd = jdate2timestamp(cdate)
|
||||
else:
|
||||
# cdate = "1403/03/03"
|
||||
# tsd = jdate2timestamp(cdate)
|
||||
continue
|
||||
# else:
|
||||
# # cdate = "1403/03/03"
|
||||
# # tsd = jdate2timestamp(cdate)
|
||||
# continue
|
||||
except:
|
||||
# print("Error in:"+ d +" for id: " + id)
|
||||
# cdate = "1403/03/03"
|
||||
# tsd = jdate2timestamp(cdate)
|
||||
continue
|
||||
import tokenizer as t
|
||||
inputString_token = t.Tokenizer.tokenize_words(None,inputString)
|
||||
# if start_date_token_index == end_date_token_index:
|
||||
# end_date_token_index += 1
|
||||
# original_date_part = inputString_token[start_date_token_index:end_date_token_index]
|
||||
# else:
|
||||
original_date_part = inputString_token[start_date_token_index:end_date_token_index + 1]
|
||||
original_date = ''
|
||||
for part in original_date_part:
|
||||
original_date = original_date + ' ' + part
|
||||
original_date = original_date.strip()
|
||||
tdates.append({"converted_date": date_item['date'],
|
||||
"date": cdate ,
|
||||
"original_date" : original_date,
|
||||
# "timestamp": tsd,
|
||||
"date_token_index": date_token_index,
|
||||
"start_date_token_index": start_date_token_index,
|
||||
"end_date_token_index":end_date_token_index})
|
||||
'''
|
||||
for d in dates:
|
||||
if not d.startswith("num"):
|
||||
try:
|
||||
tsd = jdate2timestamp(d)
|
||||
cdate = d
|
||||
except:
|
||||
try:
|
||||
d = d.replace("y", "")
|
||||
d = d.replace("m", "/")
|
||||
d = d.replace("d", "/")
|
||||
m = re.match(r"^(\d{4})\D(\d{1,2})\D(\d{1,2})$", d)
|
||||
if m:
|
||||
[year, month, day] = [
|
||||
int(m.group(1)),
|
||||
int(m.group(2)),
|
||||
int(m.group(3)),
|
||||
]
|
||||
if year > 1200 and year < 1550:
|
||||
if month < 1 or month > 12:
|
||||
month = 1
|
||||
if day < 1 or day > 31:
|
||||
day = 1
|
||||
cdate = str(year) + "/" + str(month) + "/" + str(day)
|
||||
tsd = jdate2timestamp(cdate)
|
||||
else:
|
||||
# cdate = "1403/03/03"
|
||||
# tsd = jdate2timestamp(cdate)
|
||||
continue
|
||||
else:
|
||||
# cdate = "1403/03/03"
|
||||
# tsd = jdate2timestamp(cdate)
|
||||
continue
|
||||
except:
|
||||
# print("Error in:"+ d +" for id: " + id)
|
||||
# cdate = "1403/03/03"
|
||||
# tsd = jdate2timestamp(cdate)
|
||||
continue
|
||||
tdates.append({"date": cdate, "timestamp": tsd, "index": 0, "slice": ""})'''
|
||||
return normalizedString,tdates,recognized_numbers
|
||||
|
||||
def OtherDateFormatNormalizer(inputString,pattern):
|
||||
mainTextTemp = inputString
|
||||
regex_pattern_Mah = r"y(\d{1,4})m(\d{1,2})d(\d{1,2})\sماه\s(\d{1,4})\sو\s(\d{1,3})\sو\s(\d{1,2})\sو\s(\d{1})\s" # y0m4d4 ماه 1000 و 300 و 50 و 4
|
||||
regex_pattern_MahSal = r"y(\d{1,4})m(\d{1,2})d(\d{1,2})\sماه\sسال\s(\d{1,4})\sو\s(\d{1,3})\sو\s(\d{1,2})\sو\s(\d{1})\s" # y0m4d4 ماه سال 1000 و 300 و 50 و 4
|
||||
regex_pattern_MahSal2 = r"y(\d{1,4})m(\d{1,2})d(\d{1,2})\sماه\sسال\sy(\d{1,4})m(\d{1,2})d(\d{1,2})\sو\s(\d{1,3})\sو\s(\d{1,2})\sو\s(\d{1})\s" # y0m4d4 ماه سال y1000m0d0 و 300 و 50 و 4
|
||||
regex_pattern_MahSal3 = r"y(\d{1,4})m(\d{1,2})d(\d{1,2})\sماه\sسال\sy(\d{1,4})m(\d{1,2})d(\d{1,2})" # y0m3d1 ماه سال y1353m0d0
|
||||
|
||||
if(pattern==1):
|
||||
regex = re.compile(regex_pattern_Mah)
|
||||
elif(pattern==2):
|
||||
regex = re.compile(regex_pattern_MahSal)
|
||||
elif(pattern==3):
|
||||
regex = re.compile(regex_pattern_MahSal2)
|
||||
elif(pattern==4):
|
||||
regex = re.compile(regex_pattern_MahSal3)
|
||||
|
||||
matches = regex.finditer(inputString)
|
||||
for match in matches:
|
||||
foundedPattern = match.group()
|
||||
foundedPatternTemp = match.group()
|
||||
if(pattern==1):
|
||||
foundedPattern = foundedPattern.replace('ماه','')
|
||||
else:
|
||||
foundedPattern = foundedPattern.replace('سال','')
|
||||
foundedPattern = foundedPattern.replace('ماه','')
|
||||
foundedPattern = foundedPattern.strip()
|
||||
tempString = foundedPattern
|
||||
standardDatePattern = r"y(\d{1,4})m(\d{1,2})d(\d{1,2})"
|
||||
#regex = re.compile(regex_pattern_Mah)
|
||||
matchItems = re.finditer(standardDatePattern,tempString)
|
||||
for item in matchItems:
|
||||
tempPattern = item.group()
|
||||
tempString = tempString.replace(tempPattern,'')
|
||||
tempString = tempString.strip()
|
||||
tempString = tempString.replace('و','')
|
||||
tempString = tempString.strip()
|
||||
tempArray = tempString.split()
|
||||
year = 0
|
||||
for item in tempArray:
|
||||
dateMatch = re.finditer(standardDatePattern,item)
|
||||
regexFlag = True
|
||||
for dateItem in dateMatch:
|
||||
yearStr = dateItem.group()[1:5]
|
||||
year += int(yearStr)
|
||||
regexFlag = False
|
||||
break
|
||||
if(item.isalnum() and regexFlag):
|
||||
year += int(item)
|
||||
tempPattern = tempPattern.replace('y0','y'+str(year))
|
||||
mainTextTemp = mainTextTemp.replace(foundedPatternTemp,tempPattern+' ')
|
||||
return mainTextTemp
|
||||
|
||||
#foundedPattern = jdate2timestamp(foundedPattern)
|
||||
#convertedText = regex.sub(foundedPattern,convertedText)
|
||||
|
||||
def normalizerLongData(data):
|
||||
dates = []
|
||||
if len(data) > 10000:
|
||||
textParts = textwrap.wrap(data, 10000, break_long_words=False)
|
||||
for part in textParts:
|
||||
dates.extend(normalizerData(part))
|
||||
else:
|
||||
dates = normalizerData(data)
|
||||
return dates
|
||||
|
||||
# ##################
|
||||
# در ویندوز برای اعداد منفی که تاریخهای قبلی بود را خطا می داد
|
||||
# rr = gdt.timestamp()
|
||||
# #################
|
||||
def jdate2timestamp_old(dt):
|
||||
ndt = dt.replace("y", "")
|
||||
ndt = ndt.replace("m", "/")
|
||||
ndt = ndt.replace("d", "/")
|
||||
gd = jalali.Persian(ndt).gregorian_datetime()
|
||||
# print(gd)
|
||||
ztime = datetime.time(0, 0, 0, 0)
|
||||
gdt = datetime.datetime.combine(gd, ztime)
|
||||
# print(gdt)
|
||||
rr = gdt.timestamp()
|
||||
tst = int( round(rr) * 1000)
|
||||
return tst
|
||||
|
||||
def jdate2timestamp(dt):
|
||||
ndt = dt.replace("y", "")
|
||||
ndt = ndt.replace("m", "/")
|
||||
ndt = ndt.replace("d", "/")
|
||||
gd = jalali.Persian(ndt).gregorian_datetime()
|
||||
base = datetime.date(1970, 1, 1)
|
||||
rr = (gd-base).total_seconds()
|
||||
tst = int( round(rr) * 1000)
|
||||
return tst
|
||||
|
||||
|
||||
|
||||
def getSortTimestamp(ts_date):
|
||||
empty_date = -15000000000
|
||||
ts_ts = empty_date
|
||||
try:
|
||||
if ts_date != "":
|
||||
ts_ts = jdate2timestamp(ts_date)
|
||||
except:
|
||||
ts_ts = empty_date
|
||||
|
||||
return ts_ts
|
||||
|
||||
def normalize_content(content):
|
||||
text = normalYehKe(content)
|
||||
text = _normalizer.sub_alphabets(text)
|
||||
# کلماتی که با نیم فاصله از هم جدا شده اند، را به هم می چسباند
|
||||
# در این صورت، اگر با یک اسپیس جایگزین شود، یک توکن به متن اصلی اضافه می کند
|
||||
text = sub('\u200c','',text)
|
||||
pattern = r',|٬|٫|‚|,|؟|ʕ|،|_|ـ'
|
||||
text = sub(pattern,'', text)
|
||||
|
||||
if text.__contains__('\u200c'):
|
||||
print(text)
|
||||
|
||||
return text
|
||||
|
||||
def normalYehKe(text):
|
||||
if(text == None) :
|
||||
return ''
|
||||
|
||||
c1 = sub(yeAr, yeFr, text)
|
||||
c2 = sub(keAr, keFr, c1)
|
||||
c2 = c2.replace('\u00A0', '')
|
||||
return c2.strip()
|
||||
|
||||
_term_list = []
|
||||
def setTermList():
|
||||
global _term_list
|
||||
if(_term_list.__len__() > 0):
|
||||
return
|
||||
_term_list = [
|
||||
{
|
||||
"begin": jdate2timestamp("1285/07/14"),
|
||||
"end": jdate2timestamp("1287/04/2"),
|
||||
"term": "مجلس شورای ملی-دوره1",
|
||||
"term_number": 1,
|
||||
"majles_name": "شورای ملی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1288/8/24"),
|
||||
"end": jdate2timestamp("1290/10/3"),
|
||||
"term": "مجلس شورای ملی-دوره2",
|
||||
"term_number": 2,
|
||||
"majles_name": "شورای ملی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1293/9/14"),
|
||||
"end": jdate2timestamp("1294/8/21"),
|
||||
"term": "مجلس شورای ملی-دوره3",
|
||||
"term_number": 3,
|
||||
"majles_name": "شورای ملی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1300/4/1"),
|
||||
"end": jdate2timestamp("1302/3/30"),
|
||||
"term": "مجلس شورای ملی-دوره4",
|
||||
"term_number": 4,
|
||||
"majles_name": "شورای ملی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1302/11/22"),
|
||||
"end": jdate2timestamp("1304/11/22"),
|
||||
"term": "مجلس شورای ملی-دوره5",
|
||||
"term_number": 5,
|
||||
"majles_name": "شورای ملی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1305/4/19"),
|
||||
"end": jdate2timestamp("1307/5/22"),
|
||||
"term": "مجلس شورای ملی-دوره6",
|
||||
"term_number": 6,
|
||||
"majles_name": "شورای ملی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1307/7/19"),
|
||||
"end": jdate2timestamp("1309/8/14"),
|
||||
"term": "مجلس شورای ملی-دوره7",
|
||||
"term_number": 7,
|
||||
"majles_name": "شورای ملی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1309/9/24"),
|
||||
"end": jdate2timestamp("1311/10/24"),
|
||||
"term": "مجلس شورای ملی-دوره8",
|
||||
"term_number": 8,
|
||||
"majles_name": "شورای ملی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1311/12/24"),
|
||||
"end": jdate2timestamp("1314/1/24"),
|
||||
"term": "مجلس شورای ملی-دوره9",
|
||||
"term_number": 9,
|
||||
"majles_name": "شورای ملی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1314/3/15"),
|
||||
"end": jdate2timestamp("1316/3/22"),
|
||||
"term": "مجلس شورای ملی-دوره10",
|
||||
"term_number": 10,
|
||||
"majles_name": "شورای ملی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1316/6/20"),
|
||||
"end": jdate2timestamp("1318/6/27"),
|
||||
"term": "مجلس شورای ملی-دوره11",
|
||||
"term_number": 11,
|
||||
"majles_name": "شورای ملی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1318/8/3"),
|
||||
"end": jdate2timestamp("1320/8/9"),
|
||||
"term": "مجلس شورای ملی-دوره12",
|
||||
"term_number": 12,
|
||||
"majles_name": "شورای ملی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1320/8/22"),
|
||||
"end": jdate2timestamp("1322/9/1"),
|
||||
"term": "مجلس شورای ملی-دوره13",
|
||||
"term_number": 13,
|
||||
"majles_name": "شورای ملی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1322/12/16"),
|
||||
"end": jdate2timestamp("1324/12/21"),
|
||||
"term": "مجلس شورای ملی-دوره14",
|
||||
"term_number": 14,
|
||||
"majles_name": "شورای ملی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1326/4/25"),
|
||||
"end": jdate2timestamp("1328/5/6"),
|
||||
"term": "مجلس شورای ملی-دوره15",
|
||||
"term_number": 15,
|
||||
"majles_name": "شورای ملی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1328/11/20"),
|
||||
"end": jdate2timestamp("1330/11/29"),
|
||||
"term": "مجلس شورای ملی-دوره16",
|
||||
"term_number": 16,
|
||||
"majles_name": "شورای ملی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1331/2/7"),
|
||||
"end": jdate2timestamp("1332/8/28"),
|
||||
"term": "مجلس شورای ملی-دوره17",
|
||||
"term_number": 17,
|
||||
"majles_name": "شورای ملی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1332/12/27"),
|
||||
"end": jdate2timestamp("1335/1/26"),
|
||||
"term": "مجلس شورای ملی-دوره18",
|
||||
"term_number": 18,
|
||||
"majles_name": "شورای ملی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1335/3/10"),
|
||||
"end": jdate2timestamp("1339/3/29"),
|
||||
"term": "مجلس شورای ملی-دوره19",
|
||||
"term_number": 19,
|
||||
"majles_name": "شورای ملی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1339/12/2"),
|
||||
"end": jdate2timestamp("1340/2/19"),
|
||||
"term": "مجلس شورای ملی-دوره20",
|
||||
"term_number": 20,
|
||||
"majles_name": "شورای ملی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1342/7/14"),
|
||||
"end": jdate2timestamp("1346/7/13"),
|
||||
"term": "مجلس شورای ملی-دوره21",
|
||||
"term_number": 21,
|
||||
"majles_name": "شورای ملی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1346/7/14"),
|
||||
"end": jdate2timestamp("1350/6/9"),
|
||||
"term": "مجلس شورای ملی-دوره22",
|
||||
"term_number": 22,
|
||||
"majles_name": "شورای ملی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1350/6/9"),
|
||||
"end": jdate2timestamp("1354/6/16"),
|
||||
"term": "مجلس شورای ملی-دوره23",
|
||||
"term_number": 23,
|
||||
"majles_name": "شورای ملی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1354/6/17"),
|
||||
"end": jdate2timestamp("1357/11/20"),
|
||||
"term": "مجلس شورای ملی-دوره24",
|
||||
"term_number": 24,
|
||||
"majles_name": "شورای ملی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1359/3/7"),
|
||||
"end": jdate2timestamp("1363/3/6"),
|
||||
"term": "مجلس شورای اسلامی-دوره1",
|
||||
"term_number": 1,
|
||||
"majles_name": "شورای اسلامی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1363/3/7"),
|
||||
"end": jdate2timestamp("1367/3/6"),
|
||||
"term": "مجلس شورای اسلامی-دوره2",
|
||||
"term_number": 2,
|
||||
"majles_name": "شورای اسلامی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1367/3/7"),
|
||||
"end": jdate2timestamp("1371/3/6"),
|
||||
"term": "مجلس شورای اسلامی-دوره3",
|
||||
"term_number": 3,
|
||||
"majles_name": "شورای اسلامی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1371/3/7"),
|
||||
"end": jdate2timestamp("1375/3/11"),
|
||||
"term": "مجلس شورای اسلامی-دوره4",
|
||||
"term_number": 4,
|
||||
"majles_name": "شورای اسلامی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1375/3/12"),
|
||||
"end": jdate2timestamp("1379/3/6"),
|
||||
"term": "مجلس شورای اسلامی-دوره5",
|
||||
"term_number": 5,
|
||||
"majles_name": "شورای اسلامی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1379/3/7"),
|
||||
"end": jdate2timestamp("1383/3/6"),
|
||||
"term": "مجلس شورای اسلامی-دوره6",
|
||||
"term_number": 6,
|
||||
"majles_name": "شورای اسلامی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1383/3/7"),
|
||||
"end": jdate2timestamp("1387/3/6"),
|
||||
"term": "مجلس شورای اسلامی-دوره7",
|
||||
"term_number": 7,
|
||||
"majles_name": "شورای اسلامی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1387/3/7"),
|
||||
"end": jdate2timestamp("1391/3/6"),
|
||||
"term": "مجلس شورای اسلامی-دوره8",
|
||||
"term_number": 8,
|
||||
"majles_name": "شورای اسلامی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1391/3/7"),
|
||||
"end": jdate2timestamp("1395/3/7"),
|
||||
"term": "مجلس شورای اسلامی-دوره9",
|
||||
"term_number": 9,
|
||||
"majles_name": "شورای اسلامی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1395/3/8"),
|
||||
"end": jdate2timestamp("1399/3/6"),
|
||||
"term": "مجلس شورای اسلامی-دوره10",
|
||||
"term_number": 10,
|
||||
"majles_name": "شورای اسلامی",
|
||||
},
|
||||
{
|
||||
"begin": jdate2timestamp("1399/3/7"),
|
||||
"end": jdate2timestamp("1403/3/6"),
|
||||
"term": "مجلس شورای اسلامی-دوره11",
|
||||
"term_number": 11,
|
||||
"majles_name": "شورای اسلامی",
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def getTermQanon(ts_date_timestamp, ts_ref):
|
||||
setTermList()
|
||||
global _term_list
|
||||
term = ""
|
||||
term_number = 0
|
||||
majles_name = ""
|
||||
|
||||
if ts_ref == "هيات وزيران (دوره فترت)":
|
||||
term = ts_ref
|
||||
if ts_ref == "نخست وزير (مصدق)":
|
||||
term = ts_ref
|
||||
if ts_ref == "وزير عدليه (داور)":
|
||||
term = ts_ref
|
||||
if ts_ref == "شوراي انقلاب جمهوري اسلامي ايران":
|
||||
term = ts_ref
|
||||
|
||||
majles_name = term
|
||||
if term == "":
|
||||
for i in range(len(_term_list) - 1, -1, -1):
|
||||
begin = _term_list[i]["begin"]
|
||||
end = _term_list[i]["end"]
|
||||
if ts_date_timestamp >= begin and ts_date_timestamp <= end:
|
||||
term = _term_list[i]["term"]
|
||||
term_number = _term_list[i]["term_number"]
|
||||
majles_name = _term_list[i]["majles_name"]
|
||||
break
|
||||
|
||||
error = ""
|
||||
if term == "":
|
||||
# if ts_date_timestamp >= _term_list[0]["begin"] and ts_date_timestamp <= _term_list[len(_term_list)-1]["end"] :
|
||||
if ts_date_timestamp <= _term_list[len(_term_list) - 1]["end"]:
|
||||
for i in range(0, len(_term_list) - 1, 1):
|
||||
end = _term_list[i]["end"]
|
||||
if ts_date_timestamp <= end:
|
||||
term = _term_list[i]["term"]
|
||||
term_number = _term_list[i]["term_number"]
|
||||
majles_name = _term_list[i]["majles_name"]
|
||||
error = "تاریخ بین دو دوره"
|
||||
break
|
||||
else:
|
||||
term_number = -1
|
||||
error = "تاریخ خارج از محدوده"
|
||||
|
||||
return term, term_number, majles_name, error
|
||||
|
||||
# این متد یک متن و ایندکس آغاز و پایان یک عبارت درون آن متن را دریافت می کند
|
||||
# و شماره توکن آغازین و توکن پایانی مربوط به عبارت در متن را بر می گرداند
|
||||
def token_state_finder(normalized_section_content, start_index, end_index):
|
||||
before_substring = normalized_section_content[0:start_index-1].strip()
|
||||
pattern_substring = normalized_section_content[start_index-1:end_index+1].strip()
|
||||
before_substring_token_list = before_substring.strip().split()
|
||||
pattern_token_list = pattern_substring.strip().split()
|
||||
start_token_state = len(before_substring_token_list)
|
||||
end_token_state = len(before_substring_token_list) + (len(pattern_token_list)-1)
|
||||
pattern_tokens_state ={
|
||||
"start_token_state": start_token_state,
|
||||
"end_token_state" : end_token_state
|
||||
}
|
||||
return pattern_tokens_state
|
||||
|
||||
def find_number_indexes_in_string(normalized_string,recognized_numbers):
|
||||
complete_recognized_numbers = []
|
||||
for item in recognized_numbers:
|
||||
number_start_index, number_end_index = find_token_indexes_in_string(normalized_string,item['start_token_index'],item['end_token_index'])
|
||||
content = normalized_string.split()
|
||||
# if item['start_token_index']==item['end_token_index']:
|
||||
# # حذف این بخش و باقی گذاشتن دستور ذیل الز زیر در کفایت درست کار کردن متد بررسی شود
|
||||
|
||||
# number_token_list = content[item['start_token_index']]
|
||||
# else:
|
||||
number_token_list = content[item['start_token_index']:item['end_token_index']+1]
|
||||
complete_recognized_numbers.append(
|
||||
{
|
||||
'number_value' : item['number_value'],
|
||||
'number_token_list' : number_token_list,
|
||||
'start_token_index' : item['start_token_index'],
|
||||
'end_token_index' : item['end_token_index'],
|
||||
"start_number_state": number_start_index,
|
||||
"end_number_state" : number_end_index
|
||||
}
|
||||
)
|
||||
return complete_recognized_numbers
|
||||
|
||||
# این متد متن اصلی یک متن، توکن آغازین و توکن پایانی مربوط به یک عبارت را می گیرد
|
||||
# و ایندکس آغاز و ایندکس پایان متن وارد شده را بر می گرداند
|
||||
def find_token_indexes_in_string(normalized_string,start_token_state,end_token_state):
|
||||
before_tokens = normalized_string.split()[0:start_token_state]
|
||||
content_tokens = normalized_string.split()[start_token_state:end_token_state + 1]
|
||||
content_start_index = 0
|
||||
content_end_index = 0
|
||||
# شمردن تعداد کاراکترهای هر توکن در لیست توکن قبل از عدد
|
||||
for token in before_tokens:
|
||||
content_start_index += len(token)
|
||||
# اضافه کردن تعداد فاصله های خالی یا همان اسپیس به عدد ایندکس شروع عدد
|
||||
content_start_index += len(before_tokens) + 1
|
||||
|
||||
# شمردن تعداد کاراکترهای هر توکن در لیست توکن مربوط به عدد
|
||||
for token in content_tokens:
|
||||
content_end_index += len(token)
|
||||
# اضافه کردن تعداد فاصله های خالی یا همان اسپیس به عدد ایندکس پایان عدد
|
||||
content_end_index += (content_start_index - 1) + (len(content_tokens) - 1)
|
||||
|
||||
return content_start_index, content_end_index
|
||||
|
||||
# این متد، متنی را دریافت می کند و الگوهای تعریف شده را در آن جستجو می کند و آرایه ای از عبارات مطابق با هر الگو،
|
||||
# شماره ایندکس شروع و پایان هر عبارت، عنوان و محتوای الگو، و شماره توکن شروع و توکن پایانی هر عبارت
|
||||
# پیدا شده را بر می گرداند
|
||||
def regex_patterns_finder(sectoin_content):
|
||||
regex_patterns = {
|
||||
"asle N asasi": r"اصل\s*شماره\s*(\d+)\s*قانون\s*اساسی\s*جمهوری\s*اسلامی\s*ایران", # اصل شماره فلان قانون اساسی جمهوری اسلامی ایران
|
||||
"qanone asasi": r"(?<!^)\b\sقانون\sاساسی\sجمهوری\sاسلامی\sایران", # قانون اساسی جمهوری اسلامی ایران که در اول پاراگراف نباشد
|
||||
"qanone asasi": r"(?<!^)\b\sقانون\sاساسی", # قانون اساسی که در اول پاراگراف نباشد
|
||||
"qanon * mosavvab tarikh" : r"\bقانون[\s\w/]*مصوب\s((y\d{2,4}m\d{1,2}d\d{1,2})|\d{2,4})", # قانون * مصوب تاریخ
|
||||
"in qanon" : r"این\sقانون", # این قانون
|
||||
"qanone foq" : r"قانون\sفوق", # قانون فوق
|
||||
"eslahe qanon": r"قانون\sاصلاح", # اصلاح قانون
|
||||
"tabsare foq" : r"تبصره\sفوق", # تبصره فوق
|
||||
"made foq" : r"ماده\sفوق", # ماده فوق
|
||||
"made vahede" : r"ماده\sواحده", # ماده واحده
|
||||
"made vahed" : r"ماده\sواحد", # ماده واحد
|
||||
"tabsare N" : r"^\bتبصره\s*شماره\s*(\d+)\s*", # تبصره شماره فلان که فقط اول پاراگراف باشد
|
||||
"f tabsare N" : r"(?<!^)\bتبصره\sشماره\s(\d+)\s", # تبصره شماره فلان که همه جا غیر از اول پاراگراف باشد
|
||||
"tabsare N" : r"(?<!^)\bتبصره ?\(? ?\d+? ?\)?[ :.]", # تبصره شماره فلان که همه جا غیر از اول پاراگراف باشد
|
||||
"made N" : r"(?<!^)\bماده ?\(? ?\d+? ?\)?[ :.]", # *** ماده فلان که هرجای پاراگراف غیر از اول آن باشد
|
||||
"f made N" : r"^\bماده\s*[(]?\s*(\d+)\s*[)]?\s*" # ماده فلان که فقط اول پاراگراف باشد با یا بدون ترکیب عدد با پرانتز
|
||||
}
|
||||
|
||||
matched_array = []
|
||||
for pattern_key,pattern_value in regex_patterns.items():
|
||||
regex = re.compile(pattern_value)
|
||||
matches = regex.finditer(sectoin_content)
|
||||
|
||||
for match in matches:
|
||||
# انجام عملیات مرتبط با هر الگو در اینجا
|
||||
founded_item = match.group()
|
||||
start_index = match.start() + 1
|
||||
end_index = match.end() - 1
|
||||
pattern_tokens_state = token_state_finder(sectoin_content, start_index, end_index)
|
||||
matched_array.append(
|
||||
{
|
||||
"founded_item" : founded_item,
|
||||
"start_index" : start_index,
|
||||
"end_index" : end_index,
|
||||
"pattern_key" : pattern_key,
|
||||
"pattern_value" : pattern_value,
|
||||
"start_token_state": pattern_tokens_state["start_token_state"],
|
||||
"end_token_state" : pattern_tokens_state["end_token_state"],
|
||||
}
|
||||
)
|
||||
# convertedText = regex.sub(' wwwwwwwww ',convertedText)
|
||||
# مرتب کردن آرایه بر اساس توکن شروع عبارت
|
||||
matched_array.sort(key=lambda x: int(x['start_token_state']), reverse=False)
|
||||
return matched_array
|
||||
|
||||
def change_refrece_tokens(normalized_section_content, recognized_patterns_array):
|
||||
token_list = normalized_section_content.strip().split()
|
||||
for ref_item in recognized_patterns_array:
|
||||
start_token_state = ref_item.get('start_token_state')
|
||||
end_token_state = ref_item.get('end_token_state')
|
||||
for i in range(start_token_state, end_token_state+1):
|
||||
token_list[i] = 'eeee'
|
||||
normalized_section_content = ''
|
||||
for token in token_list:
|
||||
normalized_section_content = ''.join([normalized_section_content, (' ' + token)])
|
||||
return normalized_section_content.strip()
|
||||
|
||||
def getMetaData(text):
|
||||
normalized_section_content, recognized_dates, recognized_numbers = normalizerDate2(text.strip())
|
||||
recognized_numbers = find_number_indexes_in_string(text,recognized_numbers)
|
||||
normalized_section_content = normalized_section_content.strip()
|
||||
recognized_patterns_array = regex_patterns_finder(normalized_section_content)
|
||||
normalized_section_content = change_refrece_tokens(normalized_section_content, recognized_patterns_array)
|
||||
nlp_parser = []
|
||||
date_list = recognized_dates
|
||||
ref_list = recognized_patterns_array
|
||||
for date_item in date_list:
|
||||
nlp_parser.append({
|
||||
"properties": {
|
||||
"type" : "date",
|
||||
"index_start": int(date_item['start_date_token_index']),
|
||||
"index_end" : int(date_item['end_date_token_index']),
|
||||
"text" : date_item['original_date'],
|
||||
"result" : date_item['converted_date'],
|
||||
#"timestamp" : date_item['timestamp'],
|
||||
"ref_link" : ''
|
||||
}
|
||||
})
|
||||
for ref_item in ref_list:
|
||||
nlp_parser.append({
|
||||
"properties": {
|
||||
"type" : "reference",
|
||||
"index_start" : int(ref_item['start_token_state']),
|
||||
"index_end" : int(ref_item['end_token_state']),
|
||||
"text" : ref_item['founded_item'],
|
||||
"result" : ref_item['pattern_value'],
|
||||
"ref_link" : ''
|
||||
}
|
||||
})
|
||||
return nlp_parser, normalized_section_content
|
||||
|
||||
def save_error(error_text,filename):
|
||||
with open(filename, 'a+', encoding='utf-8') as file:
|
||||
# نوشتن خطا در فایل
|
||||
file.write(error_text + '\n' + 50*'*' + '\n')
|
||||
|
||||
|
||||
|
||||
def getTitleType(caption):
|
||||
title_type = ''
|
||||
caption = normalize_content(caption)
|
||||
|
||||
if caption.startswith("الحاق ") or caption.startswith("قانون الحاق "):
|
||||
title_type = "الحاقی"
|
||||
|
||||
elif caption.startswith("اصلاح ") or caption.startswith("قانون اصلاح "):
|
||||
title_type = "اصلاحی"
|
||||
|
||||
elif caption.startswith("نظر تفسیری ") or caption.startswith("استفساریه ") or caption.startswith("تفسیر ") or caption.startswith("قانون تفسیر ") or caption.startswith("قانون استفساریه "):
|
||||
title_type = "تفسیری"
|
||||
|
||||
elif caption.startswith("تصمیم "):
|
||||
title_type = "تصمیم"
|
||||
|
||||
elif caption.startswith("نظر "):
|
||||
title_type = "نظر"
|
||||
|
||||
elif caption.startswith("نامه "):
|
||||
title_type = "نامه"
|
||||
|
||||
elif caption.startswith("قانون لغو "):
|
||||
title_type = "لغو"
|
||||
|
||||
elif caption.startswith("قانون برنامه "):
|
||||
title_type = "برنامه"
|
||||
|
||||
elif caption.startswith("قانون بودجه "):
|
||||
title_type = "بودجه"
|
||||
|
||||
elif caption.startswith("قانون حذف "):
|
||||
title_type = "حذفی"
|
||||
|
||||
elif caption.startswith("قانون تمدید "):
|
||||
title_type = "تمدیدی"
|
||||
|
||||
elif caption.startswith("قانون شمول "):
|
||||
title_type = "شمولی"
|
||||
|
||||
elif caption.startswith("قانون موقتی ") or caption.startswith("قانون موقت "):
|
||||
title_type = "موقتی"
|
||||
|
||||
elif caption.__contains__("موافقتنامه") or caption.__contains__("موافقت نامه"):
|
||||
title_type = "موافقتنامه"
|
||||
|
||||
else:
|
||||
title_type = "عادی"
|
||||
|
||||
return title_type
|
||||
|
||||
@@ -0,0 +1,192 @@
|
||||
# In The Name Of Allah
|
||||
#
|
||||
# Jalali date converter
|
||||
# 2014 07 25
|
||||
# Ported from PHP (http://jdf.scr.ir/) to Python (2&3) by Mohammad Javad Naderi <mjnaderi@gmail.com>
|
||||
#
|
||||
# As mentioned in http://jdf.scr.ir/, the original code is free and open source,
|
||||
# and you are not allowed to sell it. You can read more in http://jdf.scr.ir/.
|
||||
#
|
||||
# Original License Notes:
|
||||
#
|
||||
# /** Software Hijri_Shamsi , Solar(Jalali) Date and Time
|
||||
# Copyright(C)2011, Reza Gholampanahi , http://jdf.scr.ir
|
||||
# version 2.55 :: 1391/08/24 = 1433/12/18 = 2012/11/15 */
|
||||
#
|
||||
# /** Convertor from and to Gregorian and Jalali (Hijri_Shamsi,Solar) Functions
|
||||
# Copyright(C)2011, Reza Gholampanahi [ http://jdf.scr.ir/jdf ] version 2.50 */
|
||||
#
|
||||
# Example Usage:
|
||||
#
|
||||
# >>> import jalali
|
||||
#
|
||||
# >>> jalali.Persian('1393-1-11').gregorian_string()
|
||||
# '2014-3-31'
|
||||
# >>> jalali.Persian(1393, 1, 11).gregorian_datetime()
|
||||
# datetime.date(2014, 3, 31)
|
||||
# >>> jalali.Persian('1393/1/11').gregorian_string("{}/{}/{}")
|
||||
# '2014/3/31'
|
||||
# >>> jalali.Persian((1393, 1, 11)).gregorian_tuple()
|
||||
# (2014, 3, 31)
|
||||
#
|
||||
# >>> jalali.Gregorian('2014-3-31').persian_string()
|
||||
# '1393-1-11'
|
||||
# >>> jalali.Gregorian('2014,03,31').persian_tuple()
|
||||
# (1393, 1, 11)
|
||||
# >>> jalali.Gregorian(2014, 3, 31).persian_year
|
||||
# 1393
|
||||
|
||||
import re
|
||||
import datetime
|
||||
|
||||
|
||||
class Gregorian:
|
||||
|
||||
def __init__(self, *date):
|
||||
# Parse date
|
||||
if len(date) == 1:
|
||||
date = date[0]
|
||||
if type(date) is str:
|
||||
m = re.match(r'^(\d{4})\D(\d{1,2})\D(\d{1,2})$', date)
|
||||
if m:
|
||||
[year, month, day] = [int(m.group(1)), int(m.group(2)), int(m.group(3))]
|
||||
else:
|
||||
raise Exception("Invalid Input String")
|
||||
elif type(date) is datetime.date:
|
||||
[year, month, day] = [date.year, date.month, date.day]
|
||||
elif type(date) is tuple:
|
||||
year, month, day = date
|
||||
year = int(year)
|
||||
month = int(month)
|
||||
day = int(day)
|
||||
else:
|
||||
raise Exception("Invalid Input Type")
|
||||
elif len(date) == 3:
|
||||
year = int(date[0])
|
||||
month = int(date[1])
|
||||
day = int(date[2])
|
||||
else:
|
||||
raise Exception("Invalid Input")
|
||||
|
||||
# Check the validity of input date
|
||||
try:
|
||||
datetime.datetime(year, month, day)
|
||||
except:
|
||||
raise Exception("Invalid Date")
|
||||
|
||||
self.gregorian_year = year
|
||||
self.gregorian_month = month
|
||||
self.gregorian_day = day
|
||||
|
||||
# Convert date to Jalali
|
||||
d_4 = year % 4
|
||||
g_a = [0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]
|
||||
doy_g = g_a[month] + day
|
||||
if d_4 == 0 and month > 2:
|
||||
doy_g += 1
|
||||
d_33 = int(((year - 16) % 132) * .0305)
|
||||
a = 286 if (d_33 == 3 or d_33 < (d_4 - 1) or d_4 == 0) else 287
|
||||
if (d_33 == 1 or d_33 == 2) and (d_33 == d_4 or d_4 == 1):
|
||||
b = 78
|
||||
else:
|
||||
b = 80 if (d_33 == 3 and d_4 == 0) else 79
|
||||
if int((year - 10) / 63) == 30:
|
||||
a -= 1
|
||||
b += 1
|
||||
if doy_g > b:
|
||||
jy = year - 621
|
||||
doy_j = doy_g - b
|
||||
else:
|
||||
jy = year - 622
|
||||
doy_j = doy_g + a
|
||||
if doy_j < 187:
|
||||
jm = int((doy_j - 1) / 31)
|
||||
jd = doy_j - (31 * jm)
|
||||
jm += 1
|
||||
else:
|
||||
jm = int((doy_j - 187) / 30)
|
||||
jd = doy_j - 186 - (jm * 30)
|
||||
jm += 7
|
||||
self.persian_year = jy
|
||||
self.persian_month = jm
|
||||
self.persian_day = jd
|
||||
|
||||
def persian_tuple(self):
|
||||
return self.persian_year, self.persian_month, self.persian_day
|
||||
|
||||
def persian_string(self, date_format="{}-{}-{}"):
|
||||
return date_format.format(self.persian_year, self.persian_month, self.persian_day)
|
||||
|
||||
|
||||
class Persian:
|
||||
|
||||
def __init__(self, *date):
|
||||
# Parse date
|
||||
if len(date) == 1:
|
||||
date = date[0]
|
||||
if type(date) is str:
|
||||
m = re.match(r'^(\d{4})\D(\d{1,2})\D(\d{1,2})$', date)
|
||||
if m:
|
||||
[year, month, day] = [int(m.group(1)), int(m.group(2)), int(m.group(3))]
|
||||
else:
|
||||
raise Exception("Invalid Input String")
|
||||
elif type(date) is tuple:
|
||||
year, month, day = date
|
||||
year = int(year)
|
||||
month = int(month)
|
||||
day = int(day)
|
||||
else:
|
||||
raise Exception("Invalid Input Type")
|
||||
elif len(date) == 3:
|
||||
year = int(date[0])
|
||||
month = int(date[1])
|
||||
day = int(date[2])
|
||||
else:
|
||||
raise Exception("Invalid Input")
|
||||
|
||||
# Check validity of date. TODO better check (leap years)
|
||||
if year < 1 or month < 1 or month > 12 or day < 1 or day > 31 or (month > 6 and day == 31):
|
||||
raise Exception("Incorrect Date")
|
||||
|
||||
self.persian_year = year
|
||||
self.persian_month = month
|
||||
self.persian_day = day
|
||||
|
||||
# Convert date
|
||||
d_4 = (year + 1) % 4
|
||||
if month < 7:
|
||||
doy_j = ((month - 1) * 31) + day
|
||||
else:
|
||||
doy_j = ((month - 7) * 30) + day + 186
|
||||
d_33 = int(((year - 55) % 132) * .0305)
|
||||
a = 287 if (d_33 != 3 and d_4 <= d_33) else 286
|
||||
if (d_33 == 1 or d_33 == 2) and (d_33 == d_4 or d_4 == 1):
|
||||
b = 78
|
||||
else:
|
||||
b = 80 if (d_33 == 3 and d_4 == 0) else 79
|
||||
if int((year - 19) / 63) == 20:
|
||||
a -= 1
|
||||
b += 1
|
||||
if doy_j <= a:
|
||||
gy = year + 621
|
||||
gd = doy_j + b
|
||||
else:
|
||||
gy = year + 622
|
||||
gd = doy_j - a
|
||||
for gm, v in enumerate([0, 31, 29 if (gy % 4 == 0) else 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]):
|
||||
if gd <= v:
|
||||
break
|
||||
gd -= v
|
||||
|
||||
self.gregorian_year = gy
|
||||
self.gregorian_month = gm
|
||||
self.gregorian_day = gd
|
||||
|
||||
def gregorian_tuple(self):
|
||||
return self.gregorian_year, self.gregorian_month, self.gregorian_day
|
||||
|
||||
def gregorian_string(self, date_format="{}-{}-{}"):
|
||||
return date_format.format(self.gregorian_year, self.gregorian_month, self.gregorian_day)
|
||||
|
||||
def gregorian_datetime(self):
|
||||
return datetime.date(self.gregorian_year, self.gregorian_month, self.gregorian_day)
|
||||
File diff suppressed because one or more lines are too long
+1367
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,81 @@
|
||||
from SqlToElasticMajles.qavanin_ir.DatabaseModel import *
|
||||
import json
|
||||
import requests
|
||||
|
||||
|
||||
# این توکن بسیار مهم است. چون هر از گاهی این توکن منقضی می شود
|
||||
# و باید توکن معتبر جدید از سایت قوانین درحالت لاگین شده،
|
||||
# دریافت شود و به جای توکن زیر جایگزین شود
|
||||
TOKEN = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3MDEyNzM3NjAsImp0aSI6IkwyWWs1OFB2N3pIb3Q3eFhvK1d5VHl5VWdhZmtXMnRBIiwiaXNzIjoiaHR0cHM6XC9cL2NwLmhhbWZhaG1pLmlyIiwiZXhwIjoxNzAyNTczNzU5LCJhdWQiOiJodHRwczpcL1wvY3AuaGFtZmFobWkuaXIiLCJkYXRhIjp7ImlkIjoyLCJmaXJzdF9uYW1lIjoiXHUwNjJkXHUwNjQ1XHUwNmNjXHUwNjJmIiwibGFzdF9uYW1lIjoiXHUwNjM1XHUwNjQxXHUwNjI3XHUwNmNjXHUwNmNjIiwiZW1haWwiOiJzYWZhZWkuaGFtaWRAZ21haWwuY29tIiwidXNlcm5hbWUiOiJoc2FmYWVpIiwidXNlcl9sZXZlbCI6Mn19.17acUkUgmfGtZCN8JxkmGKzV675epTXlN9u_2QKUfEk'
|
||||
ACCEPT = "application/json"
|
||||
HEADERS = {"Authorization": TOKEN, "Accept": ACCEPT}
|
||||
|
||||
# با این متد، داده های بانک اسکیوال خوانده می شود
|
||||
def qavanin_treetext_read(startValue,count):
|
||||
import SqlToElasticMajles.qavanin_ir.DatabaseModel as dbm
|
||||
query = 'SELECT * FROM qavanin.qavanin_treetext limit %s , %s'
|
||||
# مقادیری که باید در کوئری بالا جایگزین شود
|
||||
vals = (startValue,count)
|
||||
conn = dbm.ConnectionClass('','','','')
|
||||
result = dbm.executeQueryRead(conn,query,vals)
|
||||
return result
|
||||
|
||||
# در این متد، رکورد جدول اسکیوال به یک رکورد جیسون تبدیل می شود
|
||||
def getDataRecord(record):
|
||||
dataRecord = {
|
||||
'id': 'qavanin_ir_' + str(record[5]),
|
||||
'title':str(record[1]),
|
||||
'content':str(record[2]),
|
||||
'ref_url':'https://qavanin.ir/Law/TreeText/'+str(record[3]),
|
||||
'ts_date':str(record[4]),
|
||||
'ref_id':str(record[3])
|
||||
}
|
||||
|
||||
return dataRecord
|
||||
|
||||
# این متد، داده های دریافت شده از بانک اسکیوال را در یک حلقه می اندازد
|
||||
# و آرایه ای از جیسون که در واقع همان
|
||||
# bulk_data
|
||||
# است را پر می کند
|
||||
def elasticBuckIndex(records):
|
||||
# Elasticsearch settings
|
||||
es_url = "https://api.tavasi.ir/repo/majles/qqanon/multi/add"
|
||||
# نام ایندکس(جدولی) که اطلاعات در آن ذخیره می شود
|
||||
es_index = "my_index"
|
||||
|
||||
# Bulk index the data
|
||||
bulk_data = []
|
||||
|
||||
for dataRecord in records:
|
||||
# ایجاد یک رکورد دیتا برای الاستیک
|
||||
data = getDataRecord(dataRecord)
|
||||
# اضافه کردن دیتا رکورد ایجاد شده به دیتاباک
|
||||
bulk_data.append(data)
|
||||
|
||||
|
||||
elastic_data = json.dumps(bulk_data)
|
||||
|
||||
# Send the bulk request
|
||||
response = requests.post(f"{es_url}", headers=HEADERS, data=elastic_data, timeout=600000)
|
||||
print(response.text)
|
||||
|
||||
# متد اصلی که توابع دیگر را فراخوانی می کند
|
||||
def main():
|
||||
index = 0
|
||||
x = 0
|
||||
for i in range(1,1160):
|
||||
# دریافت 10 تا رکورد از جدول قوانین
|
||||
records = qavanin_treetext_read(index,10)
|
||||
|
||||
# to elastic records
|
||||
elasticBuckIndex(records)
|
||||
|
||||
index = i * 10
|
||||
i = i + 1
|
||||
x += len(records)
|
||||
|
||||
print('تعداد رکوردهای اضافه شده به الاستیک : ' + str(x))
|
||||
print('end success')
|
||||
|
||||
# اجرای کدها ...
|
||||
main()
|
||||
@@ -0,0 +1,74 @@
|
||||
بیخبر بیخبر
|
||||
بیتوجهی بیتوجهی
|
||||
بیطرفانه بیطرفانه
|
||||
گفتوگو گفتوگو
|
||||
آنها آنها
|
||||
پیشبرد پیشبرد
|
||||
روانشناختی روانشناختی
|
||||
میباشد میباشد
|
||||
لذتبخش لذتبخش
|
||||
میدادند میدادند
|
||||
مینویسد مینویسد
|
||||
میبخشد میبخشد
|
||||
بیقاعده بیقاعده
|
||||
میباشند میباشند
|
||||
موافقتنامه موافقتنامه
|
||||
تخمگذار تخمگذار
|
||||
پایینترین پایینترین
|
||||
گرمکن گرمکن
|
||||
پیشبینی پیشبینی
|
||||
برونگرا برونگرا
|
||||
میدهد میدهد
|
||||
فیلمبرداری فیلمبرداری
|
||||
آنسوی آنسوی
|
||||
خدمتدهی خدمتدهی
|
||||
اینگونه اینگونه
|
||||
کمکرسانی کمکرسانی
|
||||
کلانشهر کلانشهر
|
||||
سپردهگذار سپردهگذار
|
||||
بنیانگذار بنیانگذار
|
||||
رضایتبخش رضایتبخش
|
||||
اصلاحطلبان اصلاحطلبان
|
||||
استخوانبندی استخوانبندی
|
||||
درونگرا درونگرا
|
||||
میگردد میگردد
|
||||
اصلاحطلب اصلاحطلب
|
||||
میتوان میتوان
|
||||
عملکرد عملکرد
|
||||
میروم میروم
|
||||
بزرگنمایی بزرگنمایی
|
||||
همجنس همجنس
|
||||
همانطور همانطور
|
||||
بیشترین بیشترین
|
||||
انسانگرایی انسانگرایی
|
||||
نمیباشند نمیباشند
|
||||
جانبداری جانبداری
|
||||
نمیتوانی نمیتوانی
|
||||
قانونگذار قانونگذار
|
||||
میشدند میشدند
|
||||
تفاهمنامه تفاهمنامه
|
||||
آسیبپذیر آسیبپذیر
|
||||
برونگرایی برونگرایی
|
||||
جفتگیری جفتگیری
|
||||
گرانبها گرانبها
|
||||
میشوند میشوند
|
||||
کلاهبرداری کلاهبرداری
|
||||
جهتیابی جهتیابی
|
||||
چشمپوشی چشمپوشی
|
||||
بنیانگذاران بنیانگذاران
|
||||
میکند میکند
|
||||
الهامبخش الهامبخش
|
||||
وقتگیر وقتگیر
|
||||
پسلرزه پسلرزه
|
||||
میکنند میکنند
|
||||
میتواند میتواند
|
||||
آرامبخش آرامبخش
|
||||
بینام بینام
|
||||
غربزدگی غربزدگی
|
||||
بیتفاوت بیتفاوت
|
||||
بیثباتی بیثباتی
|
||||
پاسخگویی پاسخگویی
|
||||
میگیرد میگیرد
|
||||
جمعبندی جمعبندی
|
||||
میشود میشود
|
||||
میکنیم میکنیم
|
||||
@@ -0,0 +1,112 @@
|
||||
مهماننوازی مهماننوازی
|
||||
صلیالله صلیالله
|
||||
موافقتنامه موافقتنامه
|
||||
اعتراضآمیز اعتراضآمیز
|
||||
رییسجمهور رییسجمهور
|
||||
چشمپوشی چشمپوشی
|
||||
هیئتعلمی هیئتعلمی
|
||||
الزامآور الزامآور
|
||||
بیمهنامه بیمهنامه
|
||||
آییننامه آییننامه
|
||||
بتنریزی بتنریزی
|
||||
تشییعجنازه تشییعجنازه
|
||||
تامینکنندگان تامینکنندگان
|
||||
پرسشنامه پرسشنامه
|
||||
تحتالشعاع تحتالشعاع
|
||||
شگفتانگیز شگفتانگیز
|
||||
بزرگنمایی بزرگنمایی
|
||||
نیمههادی نیمههادی
|
||||
قابلکنترل قابلکنترل
|
||||
روانپزشکی روانپزشکی
|
||||
ضربالمثل ضربالمثل
|
||||
اضافهکاری اضافهکاری
|
||||
اختلافنظر اختلافنظر
|
||||
بینالملل بینالملل
|
||||
یکطرفه یکطرفه
|
||||
موجشکن موجشکن
|
||||
عزتنفس عزتنفس
|
||||
بیسیم بیسیم
|
||||
شیبدار شیبدار
|
||||
دستیابی دستیابی
|
||||
روانشناختی روانشناختی
|
||||
عقبنشینی عقبنشینی
|
||||
بهطور بهطور
|
||||
خطچین خطچین
|
||||
ادراکشده ادراکشده
|
||||
خزانهداری خزانهداری
|
||||
شیمیدرمانی شیمیدرمانی
|
||||
آنسوی آنسوی
|
||||
نقطهچین نقطهچین
|
||||
منحصربهفرد منحصربهفرد
|
||||
درحالتوسعه درحالتوسعه
|
||||
رضایتبخش رضایتبخش
|
||||
قرضالحسنه قرضالحسنه
|
||||
هرجومرج هرجومرج
|
||||
سیبزمینی سیبزمینی
|
||||
میلیگرم میلیگرم
|
||||
نخستوزیر نخستوزیر
|
||||
تعیینکنندهای تعیینکنندهای
|
||||
طاقتفرسا طاقتفرسا
|
||||
قابلمشاهده قابلمشاهده
|
||||
بهوسیله بهوسیله
|
||||
قابلدستیابی قابلدستیابی
|
||||
الهامبخش الهامبخش
|
||||
پیدرپی پیدرپی
|
||||
سرمایهداری سرمایهداری
|
||||
لذتبخش لذتبخش
|
||||
تخمگذار تخمگذار
|
||||
گرمکن گرمکن
|
||||
قابلتوجهی قابلتوجهی
|
||||
فیلمبرداری فیلمبرداری
|
||||
خدمتدهی خدمتدهی
|
||||
معنیدار معنیدار
|
||||
کلانشهری کلانشهری
|
||||
گواهینامه گواهینامه
|
||||
همجنس همجنس
|
||||
همانطور همانطور
|
||||
سیستمعامل سیستمعامل
|
||||
حملونقل حملونقل
|
||||
تفاهمنامه تفاهمنامه
|
||||
بینالمللی بینالمللی
|
||||
کلاهبرداری کلاهبرداری
|
||||
نرمافزار نرمافزار
|
||||
مضافالیه مضافالیه
|
||||
قطعنامهای قطعنامهای
|
||||
پاسخگویی پاسخگویی
|
||||
عکسبرداری عکسبرداری
|
||||
پسلرزه پسلرزه
|
||||
خردهفروشی خردهفروشی
|
||||
حقوقبشر حقوقبشر
|
||||
تحلیلگران تحلیلگران
|
||||
اینگونه اینگونه
|
||||
صرفهجویی صرفهجویی
|
||||
علیالخصوص علیالخصوص
|
||||
کلانشهرها کلانشهرها
|
||||
حاصلضرب حاصلضرب
|
||||
اطلاعرسانی اطلاعرسانی
|
||||
دندانپزشکی دندانپزشکی
|
||||
پیشبرد پیشبرد
|
||||
ایدهال ایدهال
|
||||
هیچگاه هیچگاه
|
||||
صنایعدستی صنایعدستی
|
||||
سانتیمتر سانتیمتر
|
||||
پیشبینی پیشبینی
|
||||
خلیجفارس خلیجفارس
|
||||
تاریخنگاری تاریخنگاری
|
||||
هیچگونه هیچگونه
|
||||
راهاندازی راهاندازی
|
||||
جستوجوی جستوجوی
|
||||
حاشیهنشینی حاشیهنشینی
|
||||
رنگآمیزی رنگآمیزی
|
||||
جمعآوری جمعآوری
|
||||
وقتگیر وقتگیر
|
||||
آرامبخش آرامبخش
|
||||
غربزدگی غربزدگی
|
||||
کلانشهر کلانشهر
|
||||
نرمافزاری نرمافزاری
|
||||
بدینوسیله بدینوسیله
|
||||
جمعبندی جمعبندی
|
||||
گفتوگو گفتوگو
|
||||
حملونقل حملونقل
|
||||
آیتالله آیتالله
|
||||
حجتالاسلام حجتالاسلام
|
||||
@@ -0,0 +1,5 @@
|
||||
حملونقل حملونقل
|
||||
حجتالاسلاموالمسلمین حجتالاسلاموالمسلمین
|
||||
آیتاللهالعظمی آیتاللهالعظمی
|
||||
گفتوگو گفتوگو
|
||||
حملونقل حملونقل
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,4 @@
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
app = FastAPI()
|
||||
@@ -0,0 +1,136 @@
|
||||
import requests
|
||||
import json
|
||||
|
||||
from config_base import *
|
||||
from general_functions import *
|
||||
|
||||
cursor, cnxn = create_cursor('db4minaei')
|
||||
|
||||
# -----------------------------------------------------------------
|
||||
|
||||
|
||||
# BASE_URL = "https://api.tavasi.ir/list/"
|
||||
# ADD_LIST_ROUTE = "project/add"
|
||||
# ADD_ITEM_ROUTE = "subject/add"
|
||||
# TITLE = "فهرست موضوعات قانون"
|
||||
# TYPE = 3
|
||||
# ADD_LIST_QUERY = {"title": TITLE, "type": TYPE, "item_state": 1}
|
||||
GET_H = lambda x: x["HIERARCHY"]
|
||||
GET_F = lambda x: x["F_PARENTID"]
|
||||
|
||||
|
||||
# ADD_LIST_QUERY = {
|
||||
# "title": TITLE,
|
||||
# "listtype": 3,
|
||||
# "item_state": 1,
|
||||
# "ispublic" : 1,
|
||||
# }
|
||||
|
||||
# requests.post(BASE_URL + ADD_LIST_ROUTE, data=ADD_LIST_QUERY, headers = HEADERS)
|
||||
projectid = 3
|
||||
|
||||
EXAMPLE_ADD_ITEM_QUERY = {
|
||||
"title": "",
|
||||
"projectid": projectid,
|
||||
"listtype": 0,
|
||||
"parent": 0,
|
||||
}
|
||||
|
||||
|
||||
|
||||
query = """select * from dbo.[lwplan]"""
|
||||
cursor.execute(query)
|
||||
|
||||
|
||||
result = []
|
||||
|
||||
while True:
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
|
||||
HIERARCHY = row.hierarchy
|
||||
HIERARCHY = HIERARCHY.split(".")[-2]
|
||||
HIERARCHY = HIERARCHY.rjust(3, "0")
|
||||
|
||||
result.append(
|
||||
{
|
||||
"ID": int(row.ID),
|
||||
"CODE": row.CODE,
|
||||
"CAPTION": row.CAPTION,
|
||||
"F_PARENTID": int(row.F_PARENTID) if row.F_PARENTID else 0,
|
||||
"HIERARCHY": HIERARCHY,
|
||||
}
|
||||
)
|
||||
# result = sorted(result, key=GET_F)
|
||||
result = sorted(result, key=GET_H)
|
||||
|
||||
|
||||
childs = {}
|
||||
IDS_DICT = {}
|
||||
|
||||
def insert(rows):
|
||||
remains =[]
|
||||
for row in rows:
|
||||
number = 1
|
||||
try:
|
||||
F_PARENTID = row["F_PARENTID"]
|
||||
except KeyError:
|
||||
F_PARENTID = -1
|
||||
print('*'*20)
|
||||
print(row)
|
||||
print('#'*20)
|
||||
continue
|
||||
|
||||
# try:
|
||||
if F_PARENTID == 0:
|
||||
parent = 0
|
||||
elif str(F_PARENTID) in IDS_DICT:
|
||||
parent = IDS_DICT[str(F_PARENTID)]['id']
|
||||
else:
|
||||
print(F_PARENTID)
|
||||
print(IDS_DICT)
|
||||
print(row)
|
||||
break
|
||||
remains.append(row)
|
||||
continue
|
||||
|
||||
# except KeyError:
|
||||
# print('error')
|
||||
# print(row)
|
||||
# continue
|
||||
|
||||
if parent in childs:
|
||||
number = childs[parent] + 1
|
||||
childs[parent] = number
|
||||
|
||||
ADD_ITEM_QUERY = {
|
||||
"title": row["CAPTION"],
|
||||
"projectid": projectid,
|
||||
"otherid": row["ID"],
|
||||
"meta": row["CODE"],
|
||||
"childorder": number,
|
||||
"listtype": 0,
|
||||
"parent": parent,
|
||||
}
|
||||
# result = requests.post(BASE_URL + ADD_ITEM_ROUTE, data=ADD_ITEM_QUERY, headers=HEADERS)
|
||||
|
||||
New_ID = json.loads(result.text)["data"][0]["id"]
|
||||
print(str(row["ID"]) + '=' + str(New_ID))
|
||||
IDS_DICT[str(row["ID"])] = {"id" : int(New_ID), 'title': row["CAPTION"]}
|
||||
|
||||
return remains
|
||||
|
||||
remains = insert(result)
|
||||
# print(IDS_DICT)
|
||||
|
||||
count = 1
|
||||
while remains.__len__() > 0 and count < 2:
|
||||
print('##################' + str(count))
|
||||
print( remains.__len__() )
|
||||
remains = insert(remains)
|
||||
# print(IDS_DICT)
|
||||
count = count + 1
|
||||
|
||||
with open("list_Tanghih.json", 'w') as file:
|
||||
file.write(json.dumps(IDS_DICT))
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
from config_base import *
|
||||
from general_functions import *
|
||||
import requests
|
||||
|
||||
|
||||
|
||||
url = " https://api.tavasi.ir/nlp/keywords?content="
|
||||
|
||||
headers = HEADERS
|
||||
text = '''
|
||||
|
||||
دیپلماسی اقتصادی: مجموعه اقدامات و فعالیت های اقتصادی خارجی (توسط دولت یا بخش خصوصی با هماهنگی وزارت امورخارجه) که با هدف توسعه روابط اقتصادی و تجاری با کشورهای خارجی، در جهت دستیابی به اهداف نظیر افزایش دسترسی به بازارهای بین المللی کالاها و خدمات، سرمایه گذاری خارجی، تبادل فناوری و برقراری روابط پایدار با سایر کشورها انجام می شود.
|
||||
'''
|
||||
url = url + text
|
||||
payload = {}
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
entities = ''
|
||||
i = len(response.text.strip())-3
|
||||
keywords = response.text[13:i].split(',')
|
||||
# for entity in keywords:
|
||||
# entities = entities + str(entity).strip('\"') +' ' + '\n'
|
||||
print(keywords)
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import re
|
||||
|
||||
|
||||
class Tokenizer():
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def tokenize_words(self, doc_string):
|
||||
token_list = doc_string.strip().split()
|
||||
#token_list = [x.strip("\u200c").strip('\u200f') for x in token_list if len(x.strip("\u200c")) != 0]
|
||||
new_token_list = []
|
||||
new_token = ''
|
||||
for index,token in enumerate(token_list):
|
||||
if len(token.strip("\u200c")) != 0:
|
||||
new_token = token.strip("\u200c")
|
||||
if len(token.strip("\u200f")) != 0:
|
||||
new_token = new_token.strip('\u200f')
|
||||
new_token_list.append(new_token)
|
||||
return new_token_list
|
||||
|
||||
def tokenize_sentences(self, doc_string):
|
||||
#finding the numbers
|
||||
pattern = r"[-+]?\d*\.\d+|\d+"
|
||||
nums_list = re.findall(pattern, doc_string)
|
||||
doc_string = re.sub(pattern, 'floatingpointnumber', doc_string)
|
||||
|
||||
pattern = r'([!\.\?؟]+)[\n]*'
|
||||
tmp = re.findall(pattern, doc_string)
|
||||
doc_string = re.sub(pattern, self.add_tab, doc_string)
|
||||
|
||||
pattern = r':\n'
|
||||
tmp = re.findall(pattern, doc_string)
|
||||
doc_string = re.sub(pattern, self.add_tab, doc_string)
|
||||
|
||||
pattern = r';\n'
|
||||
tmp = re.findall(pattern, doc_string)
|
||||
doc_string = re.sub(pattern, self.add_tab, doc_string)
|
||||
|
||||
pattern = r'؛\n'
|
||||
tmp = re.findall(pattern, doc_string)
|
||||
doc_string = re.sub(pattern, self.add_tab, doc_string)
|
||||
|
||||
pattern = r'[\n]+'
|
||||
doc_string = re.sub(pattern, self.add_tab, doc_string)
|
||||
|
||||
for number in nums_list:
|
||||
pattern = 'floatingpointnumber'
|
||||
doc_string = re.sub(pattern, number, doc_string, 1)
|
||||
|
||||
doc_string = doc_string.split('\t\t')
|
||||
doc_string = [x for x in doc_string if len(x) > 0]
|
||||
return doc_string
|
||||
|
||||
def add_tab(self, mystring):
|
||||
mystring = mystring.group() # this method return the string matched by re
|
||||
mystring = mystring.strip(' ') # ommiting the whitespace around the pucntuation
|
||||
mystring = mystring.strip('\n') # ommiting the newline around the pucntuation
|
||||
mystring = " " + mystring + "\t\t" # adding a space after and before punctuation
|
||||
return mystring
|
||||
Reference in New Issue
Block a user