2021-02-26 Shell and python interaction

1. Python script: query the province information to be processed and output it to a file, namely file 1

#coding=utf-8
import pandas as pd
import os,sys

work_path=os.getcwd()
file1 = os.path.join(work_path,'code_list.csv')
data = pd.read_csv(file1,sep=',',index_col=0)
for i in range(3,len(sys.argv)):
    print i-2,sys.argv[1],sys.argv[2],data[data['name']==sys.argv[i]].iloc[0,0],\
    data[data['name']==sys.argv[i]].iloc[0,1]

2. Shell script: read the province information to be processed, namely file 1, call the corresponding shell script, and output the processing result to file 2; read the order information to be processed in file 2 to file 3

#!/bin/bash

FILENAME1='./'$1'to_qurry.txt'
FILENAME2='./'$1'qurry_result.txt'
FILENAME3='./'$1'result.sql'

echo > $FILENAME1
echo > $FILENAME2
echo > $FILENAME3

python diff.py $1 $2 $3 > ${FILENAME1}

while read line
do
index=`echo $line| awk '{print $1}'`
start_time=`echo $line| awk '{print $2}'`
end_time=`echo $line | awk '{print $3}'`
province_code=`echo $line | awk '{print $4}'`
province_name=`echo $line | awk '{print $5}'`
echo "开始处理${province_name}省${start_time}到${end_time}的订单......"
if [ $index == 1 ];then
sh shell1.sh $province_code $start_time $end_time   >> ${FILENAME2}
else
sh shell2.sh $province_code $start_time $end_time  >> ${FILENAME2}
fi
done < ${FILENAME1}

cat ${FILENAME2} | awk -F '\t' '{if ($3==2) printf("update %s set order_status=4 where order_code = '\''%s'\'';\n",$1,$2) }' > ${FILENAME3}
echo "处理结束."
echo "--------------------------"
echo "要处理的订单信息:"
cat ${FILENAME3}

3. Link library processing

Read the order information to be processed and connect to the database for processing.

Guess you like

Origin blog.csdn.net/weixin_38192254/article/details/114128245