inital = transfer git to git2

This commit is contained in:
hsafaei
2024-09-14 10:32:42 +03:30
commit e991cc84cb
53 changed files with 8472 additions and 0 deletions
+191
View File
@@ -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)