Floppa's i2 scripts

This commit is contained in:
April 2022-10-08 14:51:20 -07:00
parent 828247480a
commit 499491334f
No known key found for this signature in database
GPG Key ID: 17A9A017FAA4DE5E
5 changed files with 1081 additions and 0 deletions

347
Alerts.py Normal file
View File

@ -0,0 +1,347 @@
import requests
import json
import os
from datetime import datetime,timedelta
import time
import pytz
import xml.dom.minidom
import shutil
import gzip
import py2Lib.bit as bit
#Zones/Counties to fetch alerts for
interestList = ['FLZ151', 'FLC057', 'FLZ149', 'FLZ249', 'FLC101']
#You can safely edit the API key here. Make sure to include the ' before and after the key
headlineApiKey = '21d8a80b3d6b444998a80b3d6b1449d3'
detailsApiKey = '21d8a80b3d6b444998a80b3d6b1449d3'
#Where does this script live? Put path below.
#Sorry I'm too lazy to program this script figure it out itself.
path = 'D:\\PythonScripts\\Alerts'
k = 0
def getAlerts(location):
global k
fetchUrl = 'https://api.weather.com/v3/alerts/headlines?areaId=' + location + ':US&format=json&language=en-US&apiKey=' + headlineApiKey
response = requests.get(fetchUrl)
theCode = response.status_code
#Our global variables
#Set the actions based on response code
if theCode == 204:
print('No alerts for area ' + location + '.\n')
return
elif theCode == 403:
print("Uh oh! Your API key may not be authorized for alerts. Tsk Tsk. Maybe you shouldn't pirate IBM data :)\n")
return
elif theCode == 401:
print("Uh oh! This request requires authentication. Maybe you shouldn't try to access resources for IBM employee's only :)\n")
return
elif theCode == 404:
print("Uh oh! The requested resource cannot be found. This means either the URL is wrong or IBM is having technical difficulties :(\n Or.... They deleted the API :O\n")
return
elif theCode == 405:
print("Uh oh! Got a 405! This means that somehow.... someway..... this script made an invalid request. So sad..... So terrible..... :(\n")
return
elif theCode == 406:
print("Uh oh! Got a 406! This means that IBM doesn't like us. :(\n")
return
elif theCode == 408:
print("Uh oh! We were too slow in providing IBM our alert request. Although I prefer to say we were Slowly Capable! :)\n")
return
elif theCode == 500:
print("Uh oh! Seems IBM's on call IT Tech spilled coffee on the server! Looks like no alerts for a while. Please check back later :)\n")
return
elif theCode == 502 or theCode == 503 or theCode == 504:
print("Uh oh! This is why you don't have interns messing with the server configuration. Please stand by while IBM's on call IT Tech resolves the issue :)\n")
return
elif theCode == 200:
pass
#Alright lets map our headline variables.
print('Found Alert for ' + location + '\n')
dataH = response.json()
alertsRoot = dataH['alerts']
for x in alertsRoot:
detailKey = x['detailKey']
#Lets get map our detail variables.
detailsUrl = 'https://api.weather.com/v3/alerts/detail?alertId=' + detailKey + '&format=json&language=en-US&apiKey=' + detailsApiKey
detailsResponse = requests.get(detailsUrl)
dataD = detailsResponse.json()
detailsRoot = dataD['alertDetail']
theDetailsText = detailsRoot['texts']
detailsText = theDetailsText[0]
descriptionRaw = detailsText['description']
language = detailsText['languageCode']
Identifier = location + '_' + x['phenomena'] + '_' + x['significance'] + '_' + str(x['processTimeUTC'])
#Is this for a NWS Zone or County?
last4 = location[2:]
locationType = None
if 'C' in last4:
locationType = 'C'
elif 'Z' in last4:
locationType = 'Z'
#theIdent = str(Identifier)
thecheck = open(path + '\\Output\\alertmanifest.txt', "r")
check = thecheck.read()
if check.find(Identifier) != -1:
print("Alert already sent...")
return
k += 1 #We have an alert to send!
#Lets Map Our Vocal Codes!
vocalCheck = x['phenomena'] + '_' + x['significance']
vocalCode = None
if vocalCheck == 'HU_W':
vocalCode = '<bVocHdlnCd>HE001</bVocHdlnCd>'
elif vocalCheck == 'TY_W':
vocalCode = '<bVocHdlnCd>HE002</bVocHdlnCd>'
elif vocalCheck == 'HI_W':
vocalCode = '<bVocHdlnCd>HE003</bVocHdlnCd>'
elif vocalCheck == 'TO_A':
vocalCode = '<bVocHdlnCd>HE004</bVocHdlnCd>'
elif vocalCheck == 'SV_A':
vocalCode = '<bVocHdlnCd>HE005</bVocHdlnCd>'
elif vocalCheck == 'HU_A':
vocalCode = '<bVocHdlnCd>HE006</bVocHdlnCd>'
elif vocalCheck == 'TY_A':
vocalCode = '<bVocHdlnCd>HE007</bVocHdlnCd>'
elif vocalCheck == 'TR_W':
vocalCode = '<bVocHdlnCd>HE008</bVocHdlnCd>'
elif vocalCheck == 'TR_A':
vocalCode = '<bVocHdlnCd>HE009</bVocHdlnCd>'
elif vocalCheck == 'TI_W':
vocalCode = '<bVocHdlnCd>HE010</bVocHdlnCd>'
elif vocalCheck == 'HI_A':
vocalCode = '<bVocHdlnCd>HE011</bVocHdlnCd>'
elif vocalCheck == 'TI_A':
vocalCode = '<bVocHdlnCd>HE012</bVocHdlnCd>'
elif vocalCheck == 'BZ_W':
vocalCode = '<bVocHdlnCd>HE013</bVocHdlnCd>'
elif vocalCheck == 'IS_W':
vocalCode = '<bVocHdlnCd>HE014</bVocHdlnCd>'
elif vocalCheck == 'WS_W':
vocalCode = '<bVocHdlnCd>HE015</bVocHdlnCd>'
elif vocalCheck == 'HW_W':
vocalCode = '<bVocHdlnCd>HE016</bVocHdlnCd>'
elif vocalCheck == 'LE_W':
vocalCode = '<bVocHdlnCd>HE017</bVocHdlnCd>'
elif vocalCheck == 'ZR_Y':
vocalCode = '<bVocHdlnCd>HE018</bVocHdlnCd>'
elif vocalCheck == 'CF_W':
vocalCode = '<bVocHdlnCd>HE019</bVocHdlnCd>'
elif vocalCheck == 'LS_W':
vocalCode = '<bVocHdlnCd>HE020</bVocHdlnCd>'
elif vocalCheck == 'WW_Y':
vocalCode = '<bVocHdlnCd>HE021</bVocHdlnCd>'
elif vocalCheck == 'LB_Y':
vocalCode = '<bVocHdlnCd>HE022</bVocHdlnCd>'
elif vocalCheck == 'LE_Y':
vocalCode = '<bVocHdlnCd>HE023</bVocHdlnCd>'
elif vocalCheck == 'BZ_A':
vocalCode = '<bVocHdlnCd>HE024</bVocHdlnCd>'
elif vocalCheck == 'WS_A':
vocalCode = '<bVocHdlnCd>HE025</bVocHdlnCd>'
elif vocalCheck == 'FF_A':
vocalCode = '<bVocHdlnCd>HE026</bVocHdlnCd>'
elif vocalCheck == 'FA_A':
vocalCode = '<bVocHdlnCd>HE027</bVocHdlnCd>'
elif vocalCheck == 'FA_Y':
vocalCode = '<bVocHdlnCd>HE028</bVocHdlnCd>'
elif vocalCheck == 'HW_A':
vocalCode = '<bVocHdlnCd>HE029</bVocHdlnCd>'
elif vocalCheck == 'LE_A':
vocalCode = '<bVocHdlnCd>HE030</bVocHdlnCd>'
elif vocalCheck == 'SU_W':
vocalCode = '<bVocHdlnCd>HE031</bVocHdlnCd>'
elif vocalCheck == 'LS_Y':
vocalCode = '<bVocHdlnCd>HE032</bVocHdlnCd>'
elif vocalCheck == 'CF_A':
vocalCode = '<bVocHdlnCd>HE033</bVocHdlnCd>'
elif vocalCheck == 'ZF_Y':
vocalCode = '<bVocHdlnCd>HE034</bVocHdlnCd>'
elif vocalCheck == 'FG_Y':
vocalCode = '<bVocHdlnCd>HE035</bVocHdlnCd>'
elif vocalCheck == 'SM_Y':
vocalCode = '<bVocHdlnCd>HE036</bVocHdlnCd>'
elif vocalCheck == 'EC_W':
vocalCode = '<bVocHdlnCd>HE037</bVocHdlnCd>'
elif vocalCheck == 'EH_W':
vocalCode = '<bVocHdlnCd>HE038</bVocHdlnCd>'
elif vocalCheck == 'HZ_W':
vocalCode = '<bVocHdlnCd>HE039</bVocHdlnCd>'
elif vocalCheck == 'FZ_W':
vocalCode = '<bVocHdlnCd>HE040</bVocHdlnCd>'
elif vocalCheck == 'HT_Y':
vocalCode = '<bVocHdlnCd>HE041</bVocHdlnCd>'
elif vocalCheck == 'WC_Y':
vocalCode = '<bVocHdlnCd>HE042</bVocHdlnCd>'
elif vocalCheck == 'FR_Y':
vocalCode = '<bVocHdlnCd>HE043</bVocHdlnCd>'
elif vocalCheck == 'EC_A':
vocalCode = '<bVocHdlnCd>HE044</bVocHdlnCd>'
elif vocalCheck == 'EH_A':
vocalCode = '<bVocHdlnCd>HE045</bVocHdlnCd>'
elif vocalCheck == 'HZ_A':
vocalCode = '<bVocHdlnCd>HE046</bVocHdlnCd>'
elif vocalCheck == 'DS_W':
vocalCode = '<bVocHdlnCd>HE047</bVocHdlnCd>'
elif vocalCheck == 'WI_Y':
vocalCode = '<bVocHdlnCd>HE048</bVocHdlnCd>'
elif vocalCheck == 'SU_Y':
vocalCode = '<bVocHdlnCd>HE049</bVocHdlnCd>'
elif vocalCheck == 'AS_Y':
vocalCode = '<bVocHdlnCd>HE050</bVocHdlnCd>'
elif vocalCheck == 'WC_W':
vocalCode = '<bVocHdlnCd>HE051</bVocHdlnCd>'
elif vocalCheck == 'FZ_A':
vocalCode = '<bVocHdlnCd>HE052</bVocHdlnCd>'
elif vocalCheck == 'WC_A':
vocalCode = '<bVocHdlnCd>HE053</bVocHdlnCd>'
elif vocalCheck == 'AF_W':
vocalCode = '<bVocHdlnCd>HE054</bVocHdlnCd>'
elif vocalCheck == 'AF_Y':
vocalCode = '<bVocHdlnCd>HE055</bVocHdlnCd>'
elif vocalCheck == 'DU_Y':
vocalCode = '<bVocHdlnCd>HE056</bVocHdlnCd>'
elif vocalCheck == 'LW_Y':
vocalCode = '<bVocHdlnCd>HE057</bVocHdlnCd>'
elif vocalCheck == 'LS_A':
vocalCode = '<bVocHdlnCd>HE058</bVocHdlnCd>'
elif vocalCheck == 'HF_W':
vocalCode = '<bVocHdlnCd>HE059</bVocHdlnCd>'
elif vocalCheck == 'SR_W':
vocalCode = '<bVocHdlnCd>HE060</bVocHdlnCd>'
elif vocalCheck == 'GL_W':
vocalCode = '<bVocHdlnCd>HE061</bVocHdlnCd>'
elif vocalCheck == 'HF_A':
vocalCode = '<bVocHdlnCd>HE062</bVocHdlnCd>'
elif vocalCheck == 'UP_W':
vocalCode = '<bVocHdlnCd>HE063</bVocHdlnCd>'
elif vocalCheck == 'SE_W':
vocalCode = '<bVocHdlnCd>HE064</bVocHdlnCd>'
elif vocalCheck == 'SR_A':
vocalCode = '<bVocHdlnCd>HE065</bVocHdlnCd>'
elif vocalCheck == 'GL_A':
vocalCode = '<bVocHdlnCd>HE066</bVocHdlnCd>'
elif vocalCheck == 'MF_Y':
vocalCode = '<bVocHdlnCd>HE067</bVocHdlnCd>'
elif vocalCheck == 'MS_Y':
vocalCode = '<bVocHdlnCd>HE068</bVocHdlnCd>'
elif vocalCheck == 'SC_Y':
vocalCode = '<bVocHdlnCd>HE069</bVocHdlnCd>'
elif vocalCheck == 'UP_Y':
vocalCode = '<bVocHdlnCd>HE073</bVocHdlnCd>'
elif vocalCheck == 'LO_Y':
vocalCode = '<bVocHdlnCd>HE074</bVocHdlnCd>'
elif vocalCheck == 'AF_V':
vocalCode = '<bVocHdlnCd>HE075</bVocHdlnCd>'
elif vocalCheck == 'UP_A':
vocalCode = '<bVocHdlnCd>HE076</bVocHdlnCd>'
elif vocalCheck == 'TAV_W':
vocalCode = '<bVocHdlnCd>HE077</bVocHdlnCd>'
elif vocalCheck == 'TAV_A':
vocalCode = '<bVocHdlnCd>HE078</bVocHdlnCd>'
elif vocalCheck == 'TO_W':
vocalCode = '<bVocHdlnCd>HE110</bVocHdlnCd>'
else:
vocalCode = '<bVocHdlnCd />'
#Do some date/time conversions
EndTimeUTCEpoch = x['expireTimeUTC']
EndTimeUTC = datetime.utcfromtimestamp(EndTimeUTCEpoch).strftime('%Y%m%d%H%M')
#EndTimeUTC = EndTimeUTCString.astimezone(pytz.UTC)
expireTimeEpoch = x['expireTimeUTC']
expireTimeUTC = datetime.utcfromtimestamp(expireTimeEpoch).strftime('%Y%m%d%H%M')
#V3 Alert API doesn't give us issueTime in UTC. So we have to convert ourselves. Ughhh!!
iTLDTS = x['issueTimeLocal']
iTLDTO = datetime.strptime(iTLDTS, '%Y-%m-%dT%H:%M:%S%z')
issueTimeToUTC = iTLDTO.astimezone(pytz.UTC)
issueTimeUtc = issueTimeToUTC.strftime('%Y%m%d%H%M')
processTimeEpoch = x['processTimeUTC']
processTime = datetime.fromtimestamp(processTimeEpoch).strftime('%Y%m%d%H%M%S')
#What is the action of this alert?
Action = None
if x['messageType'] == 'Update':
Action = 'CON'
elif x['messageType'] == 'New':
Action = 'NEW'
#Fix description to replace new lines with space and add XML escape Chars. when needed
description = ' '.join(descriptionRaw.splitlines())
description = description.replace('&', '&amp;')
description = description.replace('<', '&lt;')
description = description.replace('>', '&gt;')
description = description.replace('-', '')
description = description.replace(':', '')
#Is this alert urgent?
urgency ='piss'
if vocalCheck == 'TO_W' or vocalCheck == 'SV_W' or vocalCheck == 'FF_W':
urgency = 'BEUrgent'
else:
urgency = 'BERecord'
alertMsg = '<BERecord id="0000" locationKey="' + location + '_' + x['phenomena'] + '_' + x['significance'] + '_' + x['eventTrackingNumber'] + '_' + x['officeCode'] + '" isWxscan="0"><action>NOT_USED</action><BEHdr><bPIL>' + x['productIdentifier'] + '</bPIL><bWMOHdr>NOT_USED</bWMOHdr><bEvent><eActionCd eActionPriority="' + str(x['messageTypeCode']) + '">' + Action + '</eActionCd><eOfficeId eOfficeNm="' + x['officeName'] + '">' + x['officeCode'] + '</eOfficeId><ePhenom>' + x['phenomena'] + '</ePhenom><eSgnfcnc>' + x['significance'] + '</eSgnfcnc><eETN>' + x['eventTrackingNumber'] + '</eETN><eDesc>' + x['eventDescription'] + '</eDesc><eStTmUTC>NOT_USED</eStTmUTC><eEndTmUTC>' + EndTimeUTC + '</eEndTmUTC><eSvrty>' + str(x['severityCode']) + '</eSvrty><eTWCIId>NOT_USED</eTWCIId><eExpTmUTC>' + expireTimeUTC + '</eExpTmUTC></bEvent><bLocations><bLocCd bLoc="' + x['areaName'] + '" bLocTyp="' + locationType + '">' + location + '</bLocCd><bStCd bSt="' + x['adminDistrict'] + '">' + x['adminDistrictCode'] + '</bStCd><bUTCDiff>NOT_USED</bUTCDiff><bTzAbbrv>NOT_USED</bTzAbbrv><bCntryCd>NOT_USED</bCntryCd></bLocations><bSgmtChksum>' + x['identifier'] + '</bSgmtChksum><procTm>' + processTime + '</procTm></BEHdr><BEData><bIssueTmUTC>' + issueTimeUtc + '</bIssueTmUTC><bHdln><bHdlnTxt>' + x['headlineText'] + '</bHdlnTxt>' + vocalCode + '</bHdln><bParameter>NOT_USED</bParameter><bNarrTxt bNarrTxtLang="en-US"><bLn>' + description + '</bLn></bNarrTxt><bSrchRslt>NOT_USED</bSrchRslt></BEData><clientKey>' + location + '_' + x['phenomena'] + '_' + x['significance'] + '_' + x['eventTrackingNumber'] + '_' + x['officeCode'] + '</clientKey></BERecord>'
#Append BERecord
with open(path + '\\Output\\BERecord.xml', "a") as b:
b.write(alertMsg)
b.close()
#Add our alert to the manifest so we don't keep sending in the same alert every 60 seconds unless an update is issued.
with open(path + '\\Output\\alertmanifest.txt', "a") as c:
c.write('\n' + location + '_' + x['phenomena'] + '_' + x['significance'] + '_' + str(x['processTimeUTC']))
c.close()
n = 0
while n==0:
#Start our XML File
with open(path + '\\Output\\BERecord.xml', "w") as e:
e.write('<Data type="BERecord">')
e.close()
for i in interestList:
getAlerts(i)
#Close our XML File
with open(path + '\\Output\\BERecord.xml', "a") as d:
d.write('</Data>')
d.close()
dom = xml.dom.minidom.parse(path + '\\Output\\BERecord.xml')
pretty_xml_as_string = dom.toprettyxml(indent = " ")
with open(path + '\\Output\\BERecord.i2m', "w") as h:
h.write(pretty_xml_as_string[23:])
h.close()
if k > 0:
with open(path + '\\Output\\BERecord.i2m', 'rb') as f_in:
with gzip.open(path + '\\Output\\BERecord.gz', 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
files = []
commands = []
gZipFile = path + '\\Output\\BERecord.gz'
files.append(gZipFile)
command = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__BERecord__,Feed=BERecord)" /><GzipCompressedMsg fname="BERecord" /></MSG>')
bit.sendFile(files, commands, 1, 0)
os.remove(gZipFile)
k = 0
os.remove(path + '\\Output\\BERecord.xml')
#os.remove(path + '\\Output\\BERecord.i2m')
print('Will sleep for 60 seconds...\n')
time.sleep(60)

120
lo8s.py Normal file
View File

@ -0,0 +1,120 @@
import py2Lib.bit as bit
import time
from datetime import datetime,timedelta
import random
theNow = datetime.now()
currentHour = theNow.strftime('%H')
def runLo8s(flavor, duration, LDL, logo = None, LDLColor = None, EmergencyLFCancel = None):
Id = ''.join(random.choice('ABCDEF0123456789') for i in range(16))
nowUTC = datetime.utcnow()
now = datetime.now()
currentHour = nowUTC.strftime('%H')
friendlyRunTime = now + timedelta(seconds=30)
runTime = nowUTC + timedelta(seconds=30)
runTimeLDL = nowUTC + timedelta(seconds=30)
ldlCancelTime = runTimeLDL.strftime('%m/%d/%Y %H:%M:%S'+':02')
lo8sRunTime = runTime.strftime('%m/%d/%Y %H:%M:%S'+':00')
friendlyLo8sRunTime = friendlyRunTime.strftime('%m/%d/%Y %I:%M:%S %p')
if flavor == 'Z':
nextLDLRunTime = runTime + timedelta(seconds=91)
else:
nextLDLRunTime = runTime + timedelta(seconds=65)
nextLDLRun = nextLDLRunTime.strftime('%m/%d/%Y %H:%M:%S'+':02')
if duration == '60':
duration = '1800'
elif duration == '65':
duration = '1950'
elif duration == '90':
duration = '2700'
elif duration == '120':
duration = '3600'
else:
print('Invalid Duration specified. Please specifiy length of the local forecast in seconds. 60 for 1 minute, 65 for 1 minute 5 seconds, 90 for 1 minute 30 seconds, 120 for 2 minutes.\n\nScript will now terminate...')
exit()
nextLDLRun = nextLDLRunTime.strftime('%m/%d/%Y %H:%M:%S'+':02')
if EmergencyLFCancel == 1:
print('Emergency Local On The 8s Kill Switch is Activated. No Local On The 8s Will Air. Maybe b3atdropp3r Hacked An i2 Again???\n' + friendlyLo8sRunTime)
time.sleep(27)
elif logo != '':
print('Sending Load Command To All Stars. The Local On The 8s is expected to start at ' + friendlyLo8sRunTime + ' ...')
bit.sendCommand(['<MSG><Exec workRequest="loadPres(File={0},VideoBehind=000,Logo=domesticAds/tag'+ logo +',Flavor=domestic/'+flavor+',Duration='+duration+',PresentationId='+Id+')" /></MSG>'], 1)
time.sleep(27)
else:
print('Sending Load Command To All Stars. The Local On The 8s is expected to start at ' + friendlyLo8sRunTime + ' ...')
bit.sendCommand(['<MSG><Exec workRequest="loadPres(File={0},VideoBehind=000,Flavor=domestic/'+flavor+',Duration='+duration+',PresentationId='+Id+')" /></MSG>'], 1)
time.sleep(27)
#Cancel LDL
print('\nCanceling LDL...')
bit.sendCommand(['<MSG><Exec workRequest="cancelPres(File={0},PresentationId=LDL,StartTime='+ldlCancelTime+')" /></MSG>'], 1)
#time.sleep(1)
if EmergencyLFCancel == 1:
print('Not Airing Local On The 8s Due To Kill Switch Activated. Will Reload LDL After National DBS Forecast Finishes...')
time.sleep(53)
else:
#Run Local On The 8s
print('\nSending The Run Command. Stand By For Your Local Forecast...')
bit.sendCommand(['<MSG><Exec workRequest="runPres(File={0},PresentationId='+Id+',StartTime='+lo8sRunTime+')" /></MSG>'], 1)
time.sleep(53)
if EmergencyLFCancel == 1:
color = None
if LDLColor == 0:
color = 'E'
elif LDLColor == 1:
color = 'F'
else:
color = 'E'
print("\nGetting The LDL Ready So It'll Cue After The National DBS Local Forecast")
bit.sendCommand(['<MSG><Exec workRequest="loadPres(File={0},Flavor=domestic/ldl'+color+',Duration=72000,PresentationId=LDL1)" /></MSG>'], 1)
time.sleep(10)
print("\nSending The Run Command For The LDL...")
bit.sendCommand(['<MSG><Exec workRequest="runPres(File={0},PresentationId=LDL1,StartTime='+nextLDLRun+')" /></MSG>'], 1)
elif LDL == 1:
color = None
if LDLColor == 0:
color = 'E'
elif LDLColor == 1:
color = 'F'
else:
color = 'E'
#Load LDL
print("\nGetting The LDL Ready So It'll Cue After This Local Forecast...")
bit.sendCommand(['<MSG><Exec workRequest="loadPres(File={0},Flavor=domestic/ldl'+color+',PresentationId=LDL1)" /></MSG>'], 1)
time.sleep(10)
#Run LDL
print('''\nSending The Run Command For The LDL. As Dave Schwartz Would Say... "That's a Wrap!"''')
bit.sendCommand(['<MSG><Exec workRequest="runPres(File={0},PresentationId=LDL1,StartTime='+nextLDLRun+')" /></MSG>'], 1)
else:
time.sleep(10)
print('''That's It Folks. As Dave Schwartz Would Say... "That's a Wrap!"''')
BG = ['3094', '3095', '3103', '3115', '3093']
#if currentHour == '22' or currentHour == '23' or currentHour == '00' or currentHour == '06' or currentHour == '07' or currentHour == '08' or currentHour == '09' or currentHour == '10' or currentHour == '11' or currentHour == '12' or currentHour == '13' or currentHour == '14' or currentHour == '15' or currentHour == '16' or currentHour == '17' or currentHour == '18' or currentHour == '19' or currentHour == '20' or currentHour == '21':
branded = random.choice(BG)
#else:
#branded = ''
#Flavor, Duration, Air LDL After Forecast (1 For Yes or 0 For No), Logo(Optional), LDL Color Mode (Leave blank for normal or 1 for Severe Mode), Emergency Local On The 8s Kill Switch (1 For Kill or leave blank for normal)
runLo8s('V2', '65', 1, branded, 1) #5053 Jonas
#V for Normal Black Logo
#V2 for Red Logo

260
py2Lib/bit.py Normal file
View File

@ -0,0 +1,260 @@
import socket
import sys
import os
import struct
import binascii
import math
import time
MCAST_GRP = '224.1.1.77'
MCAST_IF = '127.0.0.1'
BUF_SIZE = 1396
MULTICAST_TTL = 2
conn = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
conn.setsockopt(socket.SOL_IP,socket.IP_ADD_MEMBERSHIP,socket.inet_aton(MCAST_GRP)+socket.inet_aton(MCAST_IF))
test = b"This is a test"
def sendFile(files, commands, numSgmts, Pri):
if Pri == 0:
MCAST_PORT = 7787
elif Pri == 1:
MCAST_PORT = 7788
else:
print("Invalid Priority Flag. 0 = Routine Message 1 = High Priority Message\n\nScript will now terminate...")
exit()
#Get the next message ID
with open('C:\\Clips\\msgId.txt', "r") as f:
oMsgId = f.read()
msgNum = int(oMsgId)
f.close()
nMsgNum = msgNum + 1
h = open('C:\\Clips\\msgId.txt', "w")
h.write(str(nMsgNum))
h.close()
segnmNum = 0
if Pri == 0:
print("Sending Routine Msg-" + str(msgNum) + " on UDP " + MCAST_GRP + " " + str(MCAST_PORT) + "....")
elif Pri == 1:
print("Sending High Priority Msg-" + str(msgNum) + " on UDP " + MCAST_GRP + " " + str(MCAST_PORT) + "....")
startFlag = False
for x, y in zip(files, commands):
size = os.path.getsize(x)
check = size - BUF_SIZE
pToBeSent = size / 1405
packRounded = math.ceil(pToBeSent) + 1
numSegments = numSgmts + 3
total_sent = 0
payloadLength = 0
packet_count = 1
j = 0
pc = packet_count.to_bytes(1, byteorder='big')
i = 0
encode1 = bytes(y + 'I2MSG', 'UTF-8')
commandLength = len(y)
encode2 = commandLength.to_bytes(4, byteorder='little')
theCommand = b"".join([encode1, encode2])
char = ''
new_file = open(x, "ab")
new_file.write(theCommand) # Append command to end of the file
new_file.close()
new_size = os.path.getsize(x)
if startFlag == False:
#Our 34 byte beginning packet
p1 = struct.pack(">BHHHIIBBBBBBBIBIBBB", 18, 1, 0 , 16, msgNum, 0, segnmNum, 0, 0, 8, numSegments, 3, 0, 0, 8, packRounded, 0, 0, 0)
conn.sendto(p1, (MCAST_GRP, MCAST_PORT))
startFlag = True
with open(x,"rb") as message:
message.seek(0)
data = message.read(BUF_SIZE)
while data:
packetHeader = struct.pack(">BHHHIIBBB", 18, 1, 0, 1405, msgNum, packet_count, 0, 0, 0)
fec = struct.pack("<IBI", packet_count, 0, new_size)
if len(data) < BUF_SIZE:
nullCharacterLen = BUF_SIZE - len(data)
char = ''
while(i < nullCharacterLen):
char += '00'
i = i+1
theNull = bytes.fromhex(char)
conn.sendto(packetHeader + fec + data + theNull, (MCAST_GRP, MCAST_PORT))
else:
conn.sendto(packetHeader + fec + data, (MCAST_GRP, MCAST_PORT))
print(packet_count)
packet_count += 1
j += 1
#Rate Limit UDP Packets To Prevent Packet Overflow On Transport Stream.
if j == 1000: #Number of packets to be sent before pausing
time.sleep(2) #Pause for this number of seconds
j = 0
data = message.read(BUF_SIZE)
else:
data = message.read(BUF_SIZE)
segnmNum += 1
# OUR TEST MESSAGE BLOCK
#-------------------------------------------------------------------------------------------------------
w = 3
while w <= 3 and w != 0:
p3 = struct.pack(">BHHHIIBBBBBBBI", 18, 1, 1, 8, msgNum, 0, segnmNum, 0, 0, 8, 0, 0, 0, 67108864)
p4 = struct.pack(">BHHHIIBBB", 18, 1, 1, 14, msgNum, 1, segnmNum, 0, 0) + test
conn.sendto(p3, (MCAST_GRP, MCAST_PORT))
conn.sendto(p4, (MCAST_GRP, MCAST_PORT))
segnmNum += 1
w -= 1
#-------------------------------------------------------------------------------------------------------
def sendCommand(command, Pri, msgNum = None):
if Pri == 0:
MCAST_PORT = 7787
elif Pri == 1:
MCAST_PORT = 7788
else:
print("Invalid Priority Flag. 0 = Routine Message 1 = High Priority Message\n\nScript will now terminate...")
exit()
#Get the next message ID
with open('C:\\Clips\\msgId.txt', "r") as f:
oMsgId = f.read()
msgNum = int(oMsgId)
f.close()
nMsgNum = msgNum + 1
h = open('C:\\Clips\\msgId.txt', "w")
h.write(str(nMsgNum))
h.close()
segnmNum = 0
if Pri == 0:
print("Sending Routine Msg-" + str(msgNum) + " on UDP " + MCAST_GRP + " " + str(MCAST_PORT) + "....")
elif Pri == 1:
print("Sending High Priority Msg-" + str(msgNum) + " on UDP " + MCAST_GRP + " " + str(MCAST_PORT) + "....")
startFlag = False
for x in command:
bx = bytes(x, 'utf-8')
with open('D:\\command', 'wb') as c:
c.write(bx)
c.close()
size = os.path.getsize('D:\\command')
encode1 = bytes('I2MSG', 'UTF-8')
commandLength = size
encode2 = commandLength.to_bytes(4, byteorder='little')
theCommand = b"".join([encode1, encode2])
with open('D:\\command', 'ab') as d:
d.write(theCommand)
d.close()
check = size - BUF_SIZE
pToBeSent = size / 1405
packRounded = math.ceil(pToBeSent) + 1
numSegments = 4
total_sent = 0
payloadLength = 0
packet_count = 1
j = 0
pc = packet_count.to_bytes(4, byteorder='little')
i = 0
char = ''
new_size = os.path.getsize('D:\\command')
if startFlag == False:
#Our 34 byte beginning packet
p1 = struct.pack(">BHHHIIBBBBBBBIBIBBB", 18, 1, 0 , 16, msgNum, 0, segnmNum, 0, 0, 8, numSegments, 3, 0, 0, 8, packRounded, 0, 0, 0)
conn.sendto(p1, (MCAST_GRP, MCAST_PORT))
startFlag = True
with open('D:\\Command',"rb") as message:
message.seek(0)
data = message.read(BUF_SIZE)
while data:
packetHeader = struct.pack(">BHHHIIBBB", 18, 1, 0, 1405, msgNum, packet_count, 0, 0, 0)
fec = struct.pack("<IBI", packet_count, 0, new_size)
if len(data) < BUF_SIZE:
nullCharacterLen = BUF_SIZE - len(data)
char = ''
while(i < nullCharacterLen):
char += '00'
i = i+1
theNull = bytes.fromhex(char)
conn.sendto(packetHeader + fec + data + theNull, (MCAST_GRP, MCAST_PORT))
else:
conn.sendto(packetHeader + fec + data, (MCAST_GRP, MCAST_PORT))
print(packet_count)
packet_count += 1
j += 1
#Rate limit UDP Packets to prevent Packet Overflow on i2 machine.
if j == 1000: #Number of packets to be sent before pausing
time.sleep(10) #Pause for this number of seconds
j = 0
data = message.read(BUF_SIZE)
else:
data = message.read(BUF_SIZE)
segnmNum += 1
# OUR TEST MESSAGE BLOCK
#-------------------------------------------------------------------------------------------------------
w = 3
while w <= 3 and w != 0:
p3 = struct.pack(">BHHHIIBBBBBBBI", 18, 1, 1, 8, msgNum, 0, segnmNum, 0, 0, 8, 0, 0, 0, 67108864)
p4 = struct.pack(">BHHHIIBBB", 18, 1, 1, 14, msgNum, 1, segnmNum, 0, 0) + test
conn.sendto(p3, (MCAST_GRP, MCAST_PORT))
conn.sendto(p4, (MCAST_GRP, MCAST_PORT))
segnmNum += 1
w -= 1
#-------------------------------------------------------------------------------------------------------
#Send Current Observations
#sendFile("C:\\Clips\\CurrentObservations.i2m.gz", '<MSG><Exec workRequest="storeData(File={0},QGROUP=__CurrentObservations__,Feed=CurrentObservations)" /><GzipCompressedMsg fname="CurrentObservations.i2m" /></MSG>I2MSG', 0)
#time.sleep(10)
#Send Hourly Forecast
#sendFile("C:\\Clips\\HourlyForecast.i2m.gz", '<MSG><Exec workRequest="storeData(File={0},QGROUP=__HourlyForecast__,Feed=HourlyForecast)" /><GzipCompressedMsg fname="HourlyForecast.i2m" /></MSG>I2MSG', 0)
#time.sleep(10)
#Send Daily Forecast
#sendFile("C:\\Clips\\DailyForecast.i2m.gz", '<MSG><Exec workRequest="storeData(File={0},QGROUP=__DailyForecast__,Feed=DailyForecast)" /><GzipCompressedMsg fname="DailyForecast.i2m" /></MSG>I2MSG', 0)
#Send radar image
#sendFile("C:\\Clips\\radar.i2m", '<MSG><Exec workRequest="storePriorityImage(File={0},FileExtension=.tiff,IssueTime=08/28/2022 03:00:00,Location=US,ImageType=Radar)" /></MSG>I2MSG', 0)
#Load Local On The 8s
#sendCommand('<MSG><Exec workRequest="loadPres(File={0},VideoBehind=000,Logo=domesticAds/tag3352,Flavor=domestic/V,Duration=1950,PresentationId=3E396FFF95A00067)" /></MSG>I2MSG', 1)
#time.sleep(25)
#Cancel LDL
#sendCommand('<MSG><Exec workRequest="cancelPres(File={0},PresentationId=LDL,StartTime=08/29/2022 00:20:55:02)" /></MSG>I2MSG', 1)
#time.sleep(1)
#Run Local On The 8s
#sendCommand('<MSG><Exec workRequest="runPres(File={0},PresentationId=3E396FFF95A00067,StartTime=08/29/2022 00:20:55:00)" /></MSG>I2MSG', 1)
#time.sleep(35)
#Load LDL
#sendCommand('<MSG><Exec workRequest="loadPres(File={0},Flavor=domestic/ldlE,PresentationId=LDL1)" /></MSG>I2MSG', 1)
#time.sleep(10)
#Run LDL
#sendCommand('<MSG><Exec workRequest="runPres(File={0},PresentationId=LDL1,StartTime=08/29/2022 00:22:00:02)" /></MSG>I2MSG', 1)
#Heartbeat Command
#sendCommand('<MSG><Exec workRequest="heartbeat(File={0},Time=08/28/2022 02:29:00.234)" /></MSG>I2MSG', 1)
#Misc commands
#sendCommand('<MSG><Exec workRequest="loadRunPres(File={0},Flavor=domestic/ldlE,PresentationId=LDL1)" /><CheckHeadendId><HeadendId>040500</HeadendId></CheckHeadendId></MSG>I2MSG', 1)
#sendCommand('<MSG><Exec workRequest="cancelPres(File={0},PresentationId=LDL1,StartTime=08/28/2022 15:00:00:00)" /><CheckHeadendId><HeadendId>040500</HeadendId></CheckHeadendId></MSG>I2MSG', 1)
#Restart Command
#sendCommand('<MSG><Exec workRequest="restartI2Service(File={0},CommandId=0000)" /><CheckHeadendId><HeadendId>040500</HeadendId></CheckHeadendId></MSG>I2MSG', 1)
#Set ANF Mode
#sendFile("C:\\Clips\\ANFOn.i2m",'<MSG><Exec workRequest="setANFDisplay(File={0},CommandId=0000)" /><CheckHeadendId><HeadendId>040500</HeadendId><HeadendId>040449</HeadendId><HeadendId>030025</HeadendId></CheckHeadendId></MSG>I2MSG', 1)
#SendBundle
#sendFile("C:\\Clips\\Bundles.zip",'<MSG><Exec workRequest="stageStarBundle(File={0})" /></MSG>I2MSG', 0)
#Send Upgrade
#sendFile("C:\\Clips\\Upgrades\\maintenance_1.0.0.50.zip",'<MSG><Exec workRequest="storeUpgrade(File={0},ReleaseName=maintenance_1.0.0.50)" /></MSG>I2MSG', 0)
#Stage Upgrade
#sendCommand('<MSG><Exec workRequest="stageUpgrade(File={0},InstallImmediately=False,ReleaseName=maintenance_1.0.0.50)" /></MSG>I2MSG', 0)
#Change Passwords
#sendFile("C:\\Clips\\passwords.i2m",'<MSG><Exec workRequest="changePassword(File={0},CommandId=0000)" /></MSG>I2MSG', 0)

309
py2Lib/command.py Normal file
View File

@ -0,0 +1,309 @@
import bit
import os
import shutil
import math
import time
from datetime import datetime
def restartI2Service(headendIds):
HeadendList = ''
for x in headendIds:
HeadendList += ('<HeadendId>' + x + '</HeadendId>')
bit.sendCommand('<MSG><Exec workRequest="restartI2Service(File={0},CommandId=0000)" /><CheckHeadendId>' + HeadendList + '</CheckHeadendId></MSG>I2MSG', 1)
#print('<MSG><Exec workRequest="restartI2Service(File={0},CommandId=0000)" /><CheckHeadendId>' + HeadendList + '</CheckHeadendId></MSG>')
def rebootI2(headendIds):
HeadendList = ''
for x in headendIds:
HeadendList += ('<HeadendId>' + x + '</HeadendId>')
commands = []
command = '<MSG><Exec workRequest="rebootStar(File={0},CommandId=GOFUCK_YOURSELF)" /><CheckHeadendId>' + HeadendList + '</CheckHeadendId></MSG>'
commands.append(command)
bit.sendCommand(commands, 1)
def clearStarBundle(headendIds, btype):
HeadendList = ''
for x in headendIds:
HeadendList += ('<HeadendId>' + x + '</HeadendId>')
commands = []
command = '<MSG><Exec workRequest="clearStarBundle(File={0},BundleType=' + btype + ')" /><CheckHeadendId>' + HeadendList + '</CheckHeadendId></MSG>'
commands.append(command)
bit.sendCommand(commands, 1)
def changePasswords(PasswordFile, headendIds):
HeadendList = ''
files = []
files.append(PasswordFile)
commands = []
numSegs = 1
if headendIds != None:
for x in headendIds:
HeadendList += ('<HeadendId>' + x + '</HeadendId>')
command = '<MSG><Exec workRequest="changePassword(File={0},CommandId=GOFUCK_YOURSELF)" /><GzipCompressedMsg fname="passwords2.i2m" /><CheckHeadendId>' + HeadendList + '</CheckHeadendId></MSG>'
commands.append(command)
bit.sendFile(files, commands, numSegs, 0)
else:
command = '<MSG><Exec workRequest="changePassword(File={0},CommandId=GOFUCK_YOURSELF)" /><GzipCompressedMsg fname="passwords2.i2m" /></MSG>'
commands.append(command)
bit.sendFile(files, commands, numSegs, 0)
os.remove(PasswordFile)
def sendMaintCommand(File, headendIds):
HeadendList = ''
files = []
files.append(File)
commands = []
numSegs = 1
if headendIds != None:
for x in headendIds:
HeadendList += ('<HeadendId>' + x + '</HeadendId>')
#command = '<MSG><Exec workRequest="changePassword(File={0},CommandId=GOFUCK_YOURSELF)" /><GzipCompressedMsg fname="passwords" /><CheckHeadendId>' + HeadendList + '</CheckHeadendId></MSG>'
#command = '<MSG><Exec workRequest="setTsInNic(File={0},CommandId=GOFUCK_YOURSELF)" /><GzipCompressedMsg fname="TSInConfig" /><CheckHeadendId>' + HeadendList + '</CheckHeadendId></MSG>'
#command = '<MSG><Exec workRequest="setTsOutNic(File={0},CommandId=GOFUCK_YOURSELF)" /><GzipCompressedMsg fname="TSOutConfig" /><CheckHeadendId>' + HeadendList + '</CheckHeadendId></MSG>'
#command = '<MSG><Exec workRequest="setBackChannelNic(File={0},CommandId=GOFUCK_YOURSELF)" /><GzipCompressedMsg fname="BackChannelNicConfig" /><CheckHeadendId>' + HeadendList + '</CheckHeadendId></MSG>'
#command = '<MSG><Exec workRequest="setANFConfig(File={0},CommandId=GOFUCK_YOURSELF)" /><GzipCompressedMsg fname="ANFConfig" /><CheckHeadendId>' + HeadendList + '</CheckHeadendId></MSG>'
#command = '<MSG><Exec workRequest="setPipelineEncoderConfig(File={0},CommandId=GOFUCK_YOURSELF)" /><GzipCompressedMsg fname="EncoderConfig" /><CheckHeadendId>' + HeadendList + '</CheckHeadendId></MSG>'
#command = '<MSG><Exec workRequest="setPipelineDecoderConfig(File={0},CommandId=GOFUCK_YOURSELF)" /><GzipCompressedMsg fname="DecoderConfig" /><CheckHeadendId>' + HeadendList + '</CheckHeadendId></MSG>'
#I2 HD
#command = '<MSG><Exec workRequest="setTsiiConfig(File={0},DeviceType=Encoder,CommandId=GOFUCK_YOURSELF)" /><CheckHeadendId>' + HeadendList + '</CheckHeadendId></MSG>'
commands.append(command)
bit.sendFile(files, commands, numSegs, 0)
else:
#command = '<MSG><Exec workRequest="changePassword(File={0},CommandId=GOFUCK_YOURSELF)" /><GzipCompressedMsg fname="passwords.i2m" /></MSG>'
commands.append(command)
bit.sendFile(files, commands, numSegs, 0)
os.remove(File)
def loadRunPres(headendIds, Flavor, Logo, Duration, Id):
HeadendList = ''
for x in headendIds:
HeadendList += ('<HeadendId>' + x + '</HeadendId>')
if Logo == '':
command = ['<MSG><Exec workRequest="loadRunPres(File={0},Flavor='+Flavor+',Duration='+Duration+',PresentationId='+Id+')" /><CheckHeadendId>' + HeadendList + '</CheckHeadendId></MSG>']
bit.sendCommand(command, 1)
else:
command = ['<MSG><Exec workRequest="loadRunPres(File={0},Flavor='+Flavor+',Logo='+Logo+',Duration='+Duration+',PresentationId='+Id+')" /><CheckHeadendId>' + HeadendList + '</CheckHeadendId></MSG>']
bit.sendCommand(command, 1)
def sendStarBundle(File):
size = os.path.getsize(File)
if size >= 67550000:
CHUNK_SIZE = 67550000
file_number = 1
fPath = os.path.dirname(File)
fpToSplit = os.path.splitext(File)
splitFn = fpToSplit[0].split('\\')
newFn = splitFn[-1]
eCount = size / CHUNK_SIZE
estCount = math.ceil(eCount)
print("File size is greater than 64MB. Will need to split the files for transmission...\n")
time.sleep(1)
with open(File, "rb") as f:
chunk = f.read(CHUNK_SIZE)
while chunk:
if file_number < 10:
fileNum = '0' + str(file_number)
else:
fileNum = file_number
with open(fPath + '\\split\\' + newFn + '_' + str(fileNum), "wb") as chunk_file:
chunk_file.write(chunk)
print('Successfully split file ' + str(file_number) + ' out of ' + str(estCount) + '\n')
file_number += 1
chunk = f.read(CHUNK_SIZE)
count = file_number - 1
part = 1
with open('C:\\Clips\\msgId.txt', "r") as f:
oMsgId = f.read()
Id = int(oMsgId)
f.close()
for x in os.listdir(fPath + '\\split'):
path = fPath + '\\split\\'
y = path + x
if part != count:
print(x)
bit.sendFile([y],['<MSG><SplitMsg id="'+str(Id)+'" part="'+str(part)+'" count="'+str(count)+'" /></MSG>'], 1, 0)
part += 1
time.sleep(30)
elif part == count:
print(x)
bit.sendFile([y],['<MSG><SplitMsg id="'+str(Id)+'" part="'+str(part)+'" count="'+str(count)+'" /></MSG>'], 1, 0)
time.sleep(30)
bit.sendCommand(['<MSG><Exec workRequest="stageStarBundle(File=C:\\Program Files\\TWC\\i2\\Volatile\\MsgIngester-7787\\' + str(Id) + ')" /></MSG>'], 0)
for f in os.listdir(path):
os.remove(os.path.join(path, f))
else:
bit.sendFile([File],['<MSG><Exec workRequest="stageStarBundle(File={0})" /></MSG>'], 1, 0)
os.remove(File)
def sendUpgrade(File, RelName):
size = os.path.getsize(File)
if size >= 67550000:
CHUNK_SIZE = 67550000
file_number = 1
fPath = os.path.dirname(File)
fpToSplit = os.path.splitext(File)
splitFn = fpToSplit[0].split('\\')
newFn = splitFn[-1]
eCount = size / CHUNK_SIZE
estCount = math.ceil(eCount)
print("File size is greater than 64MB. Will need to split the files for transmission...\n")
time.sleep(1)
with open(File, "rb") as f:
chunk = f.read(CHUNK_SIZE)
while chunk:
if file_number < 10:
fileNum = '0' + str(file_number)
else:
fileNum = file_number
with open(fPath + '\\split\\' + newFn + '_' + str(fileNum), "wb") as chunk_file:
chunk_file.write(chunk)
print('Successfully split file ' + str(file_number) + ' out of ' + str(estCount) + '\n')
file_number += 1
chunk = f.read(CHUNK_SIZE)
count = file_number - 1
part = 1
with open('C:\\Clips\\msgId.txt', "r") as f:
oMsgId = f.read()
Id = int(oMsgId)
f.close()
for x in os.listdir(fPath + '\\split'):
path = fPath + '\\split\\'
y = path + x
if part != count:
print(x)
bit.sendFile([y],['<MSG><SplitMsg id="'+str(Id)+'" part="'+str(part)+'" count="'+str(count)+'" /></MSG>'], 1, 0)
part += 1
time.sleep(10)
elif part == count:
print(x)
bit.sendFile([y],['<MSG><SplitMsg id="'+str(Id)+'" part="'+str(part)+'" count="'+str(count)+'" /></MSG>'], 1, 0)
part += 1
time.sleep(15)
bit.sendCommand(['<MSG><Exec workRequest="storeUpgrade(File=C:\\Program Files\\TWC\\i2\\Volatile\\MsgIngester-7787\\' + str(Id) + ',ReleaseName=' + RelName + ')" /></MSG>'], 0)
for f in os.listdir(path):
os.remove(os.path.join(path, f))
else:
bit.sendFile([File],['<MSG><Exec workRequest="storeUpgrade(File={0},ReleaseName=' + RelName + ')" /></MSG>'], 1, 0)
os.remove(File)
def makeStarBundle(Directory, Type, flag, Version, date, sendAfter):
header = '<StarBundle>\n <Version>' + Version + '</Version>\n <ApplyDate>' + date + '</ApplyDate>\n <Type>' + Type + '</Type>\n <FileActions>\n'
with open('D:\\i2State\\SD\\ChangesetBundle\\MetaData\\manifest.xml', 'w') as ma:
ma.write(header)
ma.close()
for (root,dirs,files) in os.walk(Directory, topdown=True):
for name in files:
rootDir = root[24:]
bDest = os.path.join(rootDir,name)
fDest = os.path.join(root,name)
shutil.copy(fDest, 'D:\\i2State\\SD\\ChangesetBundle')
for name in files:
if flag == 'Domestic_Universe':
flag = 'flags="Domestic_Universe"'
elif flag == 'Domestic_SD_Universe':
flag = 'flags="Domestic_SD_Universe"'
else:
pass
with open('D:\\i2State\\SD\\ChangesetBundle\\MetaData\\manifest.xml', 'a') as mb:
mb.write(' <Add src="' + name + '" dest="' + bDest + '" ' + flag + ' />\n')
mb.close()
closer = ' </FileActions>\n</StarBundle>'
with open('D:\\i2State\\SD\\ChangesetBundle\\MetaData\\manifest.xml', 'a') as ma:
ma.write(closer)
ma.close()
#restartI2Service(['006833'])
#rebootI2(['006833'])
#clearStarBundle(['006833'], 'Changeset')
#bit.sendCommand(['<MSG><Exec workRequest="cancelPres(File={0},PresentationId=LDL,StartTime=09/28/2022 03:37:30:22)" /></MSG>'], 1)
#loadRunPres(['038488'], 'domestic/ldlE', '', '72000', 'LDL1')
#changePasswords('C:\\Clips\\passwords2.gz', ['006833'])
#sendMaintCommand('C:\\Clips\\maint\\temp\\passwords',['040500'])
#sendStarBundle("C:\\Clips\\Bundle.zip")
#sendUpgrade("C:\\Clips\\Upgrades\\wireshark_1.4.6.0.zip", "wireshark_1.4.6.0")
#For splitting
#sendUpgrade("C:\\Clips\\ChangesetHD.zip", "PipelineMaint_6.15.1.5714")
#For no split upgrades
#bit.sendFile('C:\\Clips\\Upgrades\\vizRequiredFilesForI2_1.2.0.0.zip', '<MSG><Exec workRequest="storeUpgrade(File={0},ReleaseName=vlc_1.1.12.0)" /><CheckHeadendId><HeadendId>040500</HeadendId></CheckHeadendId></MSG>I2MSG', 0)
#For split upgrades
#bit.sendFile('C:\\Clips\\split\\ChangesetHD_04', '<MSG><SplitMsg id="410059811" part="4" count="69" /></MSG>I2MSG', 0)
#Command for split upgrades
#commands = []
#command = '<MSG><Exec workRequest="storeUpgrade(File=C:/Program Files/TWC/i2/Volatile/MsgIngester-7787/410059791,ReleaseName=tts_1.0.0.1)" /></MSG>'
#commands.append(command)
#bit.sendCommand(commands, 1, 0)
#bit.sendFile(['C:\\Clips\\Alert.gz'], ['<MSG><Exec workRequest="storePriorityData(File={0},QGROUP=__BEUrgent__,Feed=BEUrgent)" /><GzipCompressedMsg fname="Alert.i2m" /></MSG>'], 1, 0)
'''
bit.sendCommand(['<MSG><Exec workRequest="stageUpgrade(File={0},InstallImmediately=False,ReleaseName=7zip_9.20.0.0)" /></MSG>'], 0)
bit.sendCommand(['<MSG><Exec workRequest="stageUpgrade(File={0},InstallImmediately=False,ReleaseName=agentRansack_2010.03.29.47911)" /></MSG>'], 0)
bit.sendCommand(['<MSG><Exec workRequest="stageUpgrade(File={0},InstallImmediately=False,ReleaseName=cirrusDriver_6.12.0.5645)" /></MSG>'], 0)
bit.sendCommand(['<MSG><Exec workRequest="stageUpgrade(File={0},InstallImmediately=False,ReleaseName=cirrusFirmware_6.15.0.5692)" /></MSG>'], 0)
bit.sendCommand(['<MSG><Exec workRequest="stageUpgrade(File={0},InstallImmediately=False,ReleaseName=dotNetFx40_Full_x86_x64)" /></MSG>'], 0)
bit.sendCommand(['<MSG><Exec workRequest="stageUpgrade(File={0},InstallImmediately=False,ReleaseName=fileZilla_3.4.0.0)" /></MSG>'], 0)
bit.sendCommand(['<MSG><Exec workRequest="stageUpgrade(File={0},InstallImmediately=False,ReleaseName=i2_7.4.5-release_81535)" /></MSG>'], 0)
bit.sendCommand(['<MSG><Exec workRequest="stageUpgrade(File={0},InstallImmediately=False,ReleaseName=i2PluginRuntime_7.4.1-release_19905)" /></MSG>'], 0)
bit.sendCommand(['<MSG><Exec workRequest="stageUpgrade(File={0},InstallImmediately=False,ReleaseName=i2Shell_6.3.0-release_18031)" /></MSG>'], 0)
bit.sendCommand(['<MSG><Exec workRequest="stageUpgrade(File={0},InstallImmediately=False,ReleaseName=notepad_5.9.0.0)" /></MSG>'], 0)
bit.sendCommand(['<MSG><Exec workRequest="stageUpgrade(File={0},InstallImmediately=False,ReleaseName=vizEngine_2.8.5.2988002)" /></MSG>'], 0)
bit.sendCommand(['<MSG><Exec workRequest="stageUpgrade(File={0},InstallImmediately=False,ReleaseName=vizRequiredFilesForI2_1.2.0.0)" /></MSG>'], 0)
bit.sendCommand(['<MSG><Exec workRequest="stageUpgrade(File={0},InstallImmediately=False,ReleaseName=vlc_1.1.11.0)" /></MSG>'], 0)
bit.sendCommand(['<MSG><Exec workRequest="stageUpgrade(File={0},InstallImmediately=False,ReleaseName=wireshark_1.4.6.0)" /></MSG>'], 0)
'''
#bit.sendCommand(['<MSG><Exec workRequest="cancelPres(File={0},PresentationId=LDL,StartTime=09/17/2022 02:32:40:00)" /><CheckHeadendId><HeadendId>006833</HeadendId></CheckHeadendId></MSG>'], 1)
#bit.sendCommand('C:\\Clips\\Upgrades\\split\\PipelineMaint_6.15.1.5714_03', '<MSG><Exec workRequest="storeUpgrade(File=C:/Program Files/TWC/i2/Volatile/MsgIngester-7787/410059604,ReleaseName=PipelineMaint_6.15.1.5714)" /></MSG>I2MSG', 0)
#bit.sendCommand(['<MSG><Exec workRequest="stageStarBundle(File=C:\\Program Files\\TWC\\i2\\Volatile\\MsgIngester-7787\\410069442)" /></MSG>'], 0)
#bit.sendCommand(['<MSG><Exec workRequest="loadPres(File={0},Flavor=domestic/ldlI,Duration=72000,PresentationId=ldl)" /></MSG>'], 1)
#bit.sendCommand(['<MSG><Exec workRequest="cancelPres(File={0},PresentationId=LDL,StartTime=09/25/2022 04:01:30:22)" /></MSG>'], 1)
#bit.sendCommand(['<MSG><Exec workRequest="runPres(File={0},PresentationId=ldl,StartTime=09/17/2022 17:03:35:00)" /></MSG>'], 1)
#makeStarBundle('D:\\i2State\\SD\\Changeset\\audio\\domesticSD\\vocalLocal\\Cantore', 'Changeset', 'Domestic_SD_Universe', '63702614401035937', '09/19/2022', 0)

45
py2Lib/starbundle.py Normal file
View File

@ -0,0 +1,45 @@
import os
import shutil
import random
def makeStarBundle(Directory, Type, flag, Version, date, sendAfter):
header = '<StarBundle>\n <Version>' + Version + '</Version>\n <ApplyDate>' + date + '</ApplyDate>\n <Type>' + Type + '</Type>\n <FileActions>\n'
with open('C:\\Bundle\\MetaData\\manifest.xml', 'w') as ma:
ma.write(header)
ma.close()
for (root,dirs,files) in os.walk(Directory, topdown=True):
num = 0
for name in files:
rootDir = None
if Type == "Managed":
rootDir= root[22:]
else:
rootDir = root[24:]
bDest = os.path.join(rootDir,name)
fDest = os.path.join(root,name)
signature = ''.join(random.choice('abcdef0123456789') for i in range(32))
splitExt = os.path.splitext(name)
bName = splitExt[0] + '_' + signature
shutil.copy(fDest, 'C:\\Bundle\\' + bName)
if flag == 'Domestic_Universe':
flag = 'flags="Domestic_Universe"'
elif flag == 'Domestic_SD_Universe':
flag = 'flags="Domestic_SD_Universe"'
else:
pass
with open('C:\\Bundle\\MetaData\\manifest.xml', 'a') as mb:
mb.write(' <Add src="' + bName + '" dest="' + bDest + '" ' + flag + ' />\n')
mb.close()
num += 1
closer = ' </FileActions>\n</StarBundle>'
with open('C:\\Bundle\\MetaData\\manifest.xml', 'a') as ma:
ma.write(closer)
ma.close()
#Directory which contains Files to be bundled Type Flags Version Date SendImmediately(Does not apply to this script)
makeStarBundle('D:\\i2State\\SD\\Managed\\Events', 'Managed', 'Domestic_SD_Universe', '637898877227230030', '09/28/2022', 0)