0708-雪球app抓包

课后调查表单

模拟器设置APN

jq手册

数据json

{
    "data":{
        "items":[
            {
                "market":{
                    "status_id":7,
                    "region":"CN",
                    "status":"已收盘",
                    "time_zone":"Asia/Shanghai",
                    "time_zone_desc":null
                },
                "quote":{
                    "symbol":"SH600030",
                    "code":"600030",
                    "exchange":"SH",
                    "name":"中信证券",
                    "type":11,
                    "sub_type":"ASH",
                    "status":1,
                    "current":33.5,
                    "currency":"CNY",
                    "percent":7.61,
                    "chg":2.37,
                    "timestamp":1594191600000,
                    "time":1594191600000,
                    "lot_size":100,
                    "tick_size":0.01,
                    "open":31.22,
                    "last_close":31.13,
                    "high":34.24,
                    "low":31.22,
                    "avg_price":32.566,
                    "volume":690476415,
                    "amount":2.2486166562E10,
                    "turnover_rate":7.04,
                    "amplitude":9.7,
                    "market_capital":4.33046996972E11,
                    "float_market_capital":3.2879116695E11,
                    "total_shares":12926776029,
                    "float_shares":9814661700,
                    "issue_date":1041782400000,
                    "lock_set":0,
                    "current_year_percent":32.41,
                    "high52w":34.24,
                    "low52w":20.16,
                    "limit_up":34.24,
                    "limit_down":28.02,
                    "volume_ratio":1.18,
                    "eps":0.93,
                    "pe_ttm":35.948,
                    "pe_forecast":26.564,
                    "pe_lyr":35.413,
                    "navps":13.72,
                    "pb":2.442,
                    "dividend":0.5,
                    "dividend_yield":1.493,
                    "profit":1.222860972382E10,
                    "profit_four":1.204653997635E10,
                    "profit_forecast":1.6302122163E10,
                    "pledge_ratio":0.19,
                    "goodwill_in_net_assets":6.216261059290995
                },
                "tags":[
                ]
            },
            {
                "market":{
                    "status_id":7,
                    "region":"CN",
                    "status":"已收盘",
                    "time_zone":"Asia/Shanghai",
                    "time_zone_desc":null
                },
                "quote":{
                    "symbol":"SH601318",
                    "code":"601318",
                    "exchange":"SH",
                    "name":"中国平安",
                    "type":11,
                    "sub_type":"ASH",
                    "status":1,
                    "current":85.69,
                    "currency":"CNY",
                    "percent":2.97,
                    "chg":2.47,
                    "timestamp":1594191600000,
                    "time":1594191600000,
                    "lot_size":100,
                    "tick_size":0.01,
                    "open":84.11,
                    "last_close":83.22,
                    "high":87.0,
                    "low":83.85,
                    "avg_price":85.396,
                    "volume":169638993,
                    "amount":1.4486522558E10,
                    "turnover_rate":1.57,
                    "amplitude":3.79,
                    "market_capital":1.566433886423E12,
                    "float_market_capital":9.28251020834E11,
                    "total_shares":18280241410,
                    "float_shares":10832664498,
                    "issue_date":1172678400000,
                    "lock_set":null,
                    "current_year_percent":2.08,
                    "high52w":90.8555,
                    "low52w":64.8266,
                    "limit_up":91.54,
                    "limit_down":74.9,
                    "volume_ratio":0.92,
                    "eps":7.11,
                    "pe_ttm":12.054,
                    "pe_forecast":15.025,
                    "pe_lyr":10.484,
                    "navps":37.76,
                    "pb":2.269,
                    "dividend":2.05,
                    "dividend_yield":2.392,
                    "profit":1.49407E11,
                    "profit_four":1.29953E11,
                    "profit_forecast":1.04252E11,
                    "pledge_ratio":3.52,
                    "goodwill_in_net_assets":3.030153753426563
                },
                "tags":[
                ]
            },
            {
                "market":{
                    "status_id":7,
                    "region":"CN",
                    "status":"已收盘",
                    "time_zone":"Asia/Shanghai",
                    "time_zone_desc":null
                },
                "quote":{
                    "symbol":"SH601788",
                    "code":"601788",
                    "exchange":"SH",
                    "name":"光大证券",
                    "type":11,
                    "sub_type":"ASH",
                    "status":1,
                    "current":27.3,
                    "currency":"CNY",
                    "percent":9.99,
                    "chg":2.48,
                    "timestamp":1594191600000,
                    "time":1594191600000,
                    "lot_size":100,
                    "tick_size":0.01,
                    "open":24.82,
                    "last_close":24.82,
                    "high":27.3,
                    "low":24.5,
                    "avg_price":26.273,
                    "volume":294039824,
                    "amount":7.725432417E9,
                    "turnover_rate":7.53,
                    "amplitude":11.28,
                    "market_capital":1.25874502545E11,
                    "float_market_capital":1.06652878305E11,
                    "total_shares":4610787639,
                    "float_shares":3906698839,
                    "issue_date":1250524800000,
                    "lock_set":null,
                    "current_year_percent":108.4,
                    "high52w":27.3,
                    "low52w":10.13,
                    "limit_up":27.3,
                    "limit_down":22.34,
                    "volume_ratio":1.19,
                    "eps":0.08,
                    "pe_ttm":355.089,
                    "pe_forecast":28.51,
                    "pe_lyr":221.632,
                    "navps":10.51,
                    "pb":2.598,
                    "dividend":0.037,
                    "dividend_yield":0.136,
                    "profit":5.679448863E8,
                    "profit_four":3.5448724321E8,
                    "profit_forecast":4.415168748E9,
                    "pledge_ratio":0.13,
                    "goodwill_in_net_assets":2.1573348814411872
                },
                "tags":[
                ]
            },
            {
                "market":{
                    "status_id":7,
                    "region":"CN",
                    "status":"已收盘",
                    "time_zone":"Asia/Shanghai",
                    "time_zone_desc":null
                },
                "quote":{
                    "symbol":"SZ000651",
                    "code":"000651",
                    "exchange":"SZ",
                    "name":"格力电器",
                    "type":11,
                    "sub_type":"1",
                    "status":1,
                    "current":59.49,
                    "currency":"CNY",
                    "percent":-0.98,
                    "chg":-0.59,
                    "timestamp":1594191843000,
                    "time":1594191843000,
                    "lot_size":100,
                    "tick_size":0.01,
                    "open":60.0,
                    "last_close":60.08,
                    "high":60.8,
                    "low":58.65,
                    "avg_price":59.23,
                    "volume":127042154,
                    "amount":7.52413391221E9,
                    "turnover_rate":2.13,
                    "amplitude":3.58,
                    "market_capital":3.57875829932E11,
                    "float_market_capital":3.55163033878E11,
                    "total_shares":6015730878,
                    "float_shares":5970130003,
                    "issue_date":848246400000,
                    "lock_set":null,
                    "current_year_percent":-7.47,
                    "high52w":69.1765,
                    "low52w":47.451,
                    "limit_up":66.09,
                    "limit_down":54.07,
                    "volume_ratio":1.14,
                    "eps":3.42,
                    "pe_ttm":17.387,
                    "pe_forecast":57.425,
                    "pe_lyr":14.491,
                    "navps":18.77,
                    "pb":3.169,
                    "dividend":1.2,
                    "dividend_yield":2.017,
                    "profit":2.469664136884E10,
                    "profit_four":2.058278586676E10,
                    "profit_forecast":6.232054156E9,
                    "pledge_ratio":15.73,
                    "goodwill_in_net_assets":0.2885678941310781
                },
                "tags":[
                ]
            },
            {
                "market":{
                    "status_id":7,
                    "region":"CN",
                    "status":"已收盘",
                    "time_zone":"Asia/Shanghai",
                    "time_zone_desc":null
                },
                "quote":{
                    "symbol":"SZ002049",
                    "code":"002049",
                    "exchange":"SZ",
                    "name":"紫光国微",
                    "type":11,
                    "sub_type":"2",
                    "status":1,
                    "current":120.6,
                    "currency":"CNY",
                    "percent":2.94,
                    "chg":3.44,
                    "timestamp":1594191843000,
                    "time":1594191843000,
                    "lot_size":100,
                    "tick_size":0.01,
                    "open":115.0,
                    "last_close":117.16,
                    "high":126.7,
                    "low":108.0,
                    "avg_price":116.22,
                    "volume":79793343,
                    "amount":9.27375596024E9,
                    "turnover_rate":13.16,
                    "amplitude":15.96,
                    "market_capital":7.3182246941E10,
                    "float_market_capital":7.3111626837E10,
                    "total_shares":606817968,
                    "float_shares":606232395,
                    "issue_date":1117987200000,
                    "lock_set":null,
                    "current_year_percent":137.21,
                    "high52w":126.7,
                    "low52w":41.5,
                    "limit_up":128.88,
                    "limit_down":105.44,
                    "volume_ratio":2.1,
                    "eps":0.87,
                    "pe_ttm":138.399,
                    "pe_forecast":96.25,
                    "pe_lyr":180.358,
                    "navps":7.21,
                    "pb":16.727,
                    "dividend":0.068,
                    "dividend_yield":0.056,
                    "profit":4.0576178209E8,
                    "profit_four":5.2877635668E8,
                    "profit_forecast":7.6033436E8,
                    "pledge_ratio":0.0,
                    "goodwill_in_net_assets":15.663801303018865
                },
                "tags":[
                ]
            },
            {
                "market":{
                    "status_id":7,
                    "region":"CN",
                    "status":"已收盘",
                    "time_zone":"Asia/Shanghai",
                    "time_zone_desc":null
                },
                "quote":{
                    "symbol":"SZ300059",
                    "code":"300059",
                    "exchange":"SZ",
                    "name":"东方财富",
                    "type":11,
                    "sub_type":"3",
                    "status":1,
                    "current":25.94,
                    "currency":"CNY",
                    "percent":10.01,
                    "chg":2.36,
                    "timestamp":1594191843000,
                    "time":1594191843000,
                    "lot_size":100,
                    "tick_size":0.01,
                    "open":23.95,
                    "last_close":23.58,
                    "high":25.94,
                    "low":23.92,
                    "avg_price":24.783,
                    "volume":540681066,
                    "amount":1.339986949105E10,
                    "turnover_rate":8.26,
                    "amplitude":8.57,
                    "market_capital":2.09043466213E11,
                    "float_market_capital":1.69780021521E11,
                    "total_shares":8058730386,
                    "float_shares":6545104916,
                    "issue_date":1268928000000,
                    "lock_set":0,
                    "current_year_percent":97.72,
                    "high52w":25.94,
                    "low52w":10.6988,
                    "limit_up":25.94,
                    "limit_down":21.22,
                    "volume_ratio":0.93,
                    "eps":0.29,
                    "pe_ttm":90.135,
                    "pe_forecast":59.816,
                    "pe_lyr":114.151,
                    "navps":2.74,
                    "pb":9.467,
                    "dividend":0.025,
                    "dividend_yield":0.096,
                    "profit":1.83128885132E9,
                    "profit_four":2.31921464026E9,
                    "profit_forecast":3.49475696E9,
                    "pledge_ratio":6.59,
                    "goodwill_in_net_assets":12.725613403302868
                },
                "tags":[
                ]
            }],
        "items_size":6
    },
    "error_code":0,
    "error_description":""
}


作业

1.修改股票列表页某支股票的名字(正常修改、null值修改、控制修改)

cat s.json | jq '.data.items[0].quote.name=null' | jq '.data.items[1].quote.name=" "' >stockstr.json

2.修改股票列表页某支股票的价格(上涨、下跌、负数、小数)

cat stock.json | jq '.data.items[0].quote.current+=1000' | jq '.data.items[1].quote.current-=300' | jq '.data.items[2].quote.current=-2000' | jq '.data.items[3].quote.current=3.1415926' >stocknum.json

3.针对股票列表页批量操作(列表页股票清空、剩1支、倍增千倍)

周六提前预习

惯例占楼

cat stock.json | jq ‘.data.items[0].current+=20’

cat stock.json | jq ‘.data.items[1].current-=10’

cat stock.json | jq ‘.data.items[0].current+=20’ | jq ‘.data.items[1].current-=10’ | jq ‘.data.items[2].percent=-44’
| jq ‘.data.items[3].percent=44’

2 Likes

第二题:股票上涨值变为原来正负相反的数字

cat stock.json | jq ".data.items[0].quote.percent*=-1" > stock1.json

这个是正常的:

cat stock.json | jq "{(.data.items[4].quote.name) : (.data.items[4].quote.percent)}"

这样就笛卡尔积了,怎么破?

cat stock.json | jq "{(.data.items[].quote.name) : (.data.items[].quote.percent)}"

这应该是需要 jq 有类似 sql 进行 inner join 关联查询了吧,mongdb 是以 json 格式存储数据的,都不支持关联查询,不知道 jq 行不行。。。

作业(针对股票列表页批量操作(列表页股票清空、剩1支、倍增千倍))

  1. 清空
jq '.data.items=[] | .data.items_size=0' stock.json
  1. 剩1只股票
jq '.data.items=.data.items[0] | .data.items_size=1' stock.json
  1. 倍增

3.1 生成 $.data.items_size * 2 的数量

jq '.data.items+=.data.items | .data.items_size+=.data.items_size' stock.json

3.2 根据原 $.data.items_size 的数量,生成 $.data.items_size * 2^n 的数量

content=`cat stock.json`
n=3
for i in $(seq 1 $n)
do
  content=`echo $content | jq '.data.items+=.data.items | .data.items_size+=.data.items_size'`
done
echo $content | jq .

3.3 根据原$.data.items_size 的数量,生成 $.data.items_size * n 的数量

content=`cat stock.json`
items=`jq --compact-output '.data.items' stock.json`
items_size=`jq '.data.items_size' stock.json`
n=3
for i in $(seq 1 $n)
do
  content=`echo $content | jq --argjson items $items --argjson items_size $items_size '.data.items+=$items | .data.items_size+=$items_size'`
done
echo $content | jq .

作业(针对股票列表页批量操作(列表页股票清空、剩1支、倍增千倍))

1.清空

cat stock.json | jq ".data.items=[]" | jq ".data.items_size=0"

2.剩1支

cat stock.json | jq "del(.data.items[1:])" | jq ".data.items_size=1"

3.倍增千倍

cat stock.json | jq "until(.data.items | length >= 1000; .data.items+=.data.items)" | jq ".data.items_size = (.data.items | length)" | jq "[(.data.items | length), .data.items_size]"

课后作业:
针对股票列表页批量操作(列表页股票清空、剩1支、倍增千倍)
清空:
cat stock.json | jq ‘.data.items=[]’ | jq ‘.data.items_size=0’

剩余第二个股票:
cat stock.json | jq ‘.data.items=.data.items[1]’ | jq ‘.data.items_size=1’

倍增:可多次执行以达到数量变多的情况
cat stock.json | jq ‘.data.items+=.data.items’ | jq ‘.data.items_size+=.data.items_size’

先取出所有的数据。通过管道传递给下一个,然后再数据重组。这样就不会有笛卡尔积了

cat stock.json | jq '.data.items[]' | jq '{(.quote.name):(.quote.percent)}'
1 Like

Windows环境把jq-win64.exe 改名为jq.exe 添加到系统Path,然后执行作业代码如下:

1.清空
type xueqiu_stock.json | jq ".data.items=[]" | jq ".data.items_size=0"

2.剩1支
type xueqiu_stock.json | jq ".data.items=.data.items[0]" | jq ".data.items_size=1"  

3.倍增
type xueqiu_stock.json | jq ".data.items+=.data.items" | jq ".data.items_size+=.data.items_size"

倍增写的不太全哟

作业1

cat xueqiu.json |jq '.data.items[0].quote.name="欢乐的测试呀"' |jq '.data.items[1].quote.name=null'|jq '.data.items[2].quote.name=" "' > xueqiuname.json

作业2
cat xueqiu.json |jq '.data.items[0].quote.current+=1000' |jq '.data.items[1].quote.current-=1000'|jq '.data.items[2].quote.current-=2000' | jq '.data.items[3].quote.current*=0.0001' > xueqiucurrent.json
作业3
清空
cat xueqiu.json |jq '.data.items=[]'|jq '.data.items_size=0' > xueqiulistnull.json
剩1只股票
cat xueqiu.json |jq '.data.items=[.data.items[0]]'|jq '.data.items_size=1' > xueqiulistone.json
倍增
cat xueqiu.json |jq '.data.items+=.data.items'|jq '.data.items_size+=.data.items_size' > xueqiulistdouble.json

课后作业

清空
less old_stock.json | jq '.data.items=[]' | jq '.data.items_size=0' > new_stock.json
剩1支
less old_stock.json | jq '.data.items[0]' | jq '.data.items_size=1' > new_stock.json
倍增
less old_stock.json | jq '.data.items+=.data.items' | jq '.data.items_size+=.data.items_size' > new_stock.json

这个问题,是需要使用jq的入参来实现吗?
目标是 条数 * n 吗?

  • 列表页股票清空
cat stock.json |jq '.data.items=[]' | jq '.data.items_size=0' > stockstr.json
  • 剩1支
cat stock.json |jq '.data.items[1:]=[]' | jq '.data.items_size=1' > stockstr.json
  • 倍增千倍
cat stock.json |jq '.data.items_size*=1000' |jq 'until((.data.items | length) > .data.items_size; .data.items += .data.items)' > stockstr.json

1.列表股票清空

cat stock.json | jq '.data.items=[]' | jq '.data.items_size=0'

2.列表剩余一支股票(留下第一只股票)

cat stock.json | jq '.data.items[0]' | jq '.data.items_size=1'

3.倍增千倍

cat stock.json | jq '.data.items[].quote.current=(.data.items[].quote.current*1000)'

1.列表清空
cat stock.json | jq ‘del(.data.items[])’ | jq ‘.data.items_size=0’

2.只留一只股票
删掉只留一只
cat stock.json | jq ‘del(.data.items[0,1,2,3,4])’ | jq '.data.items_size=1

重新赋值留一只
cat stock.json | jq ‘.data.items=[.data.items[0]]’ | jq ‘.data.items_size=1’

3.倍增千倍
将已有数据进行循环复制
cat stock.json | jq ‘until((.data.items | length) > 6000; .data.items=.data.items+.data.items)’ | jq ‘.data.items_size=(.data.items|length)’

1.修改股票列表页某支股票的名字(正常修改、null值修改、控制修改)
2.修改股票列表页某支股票的价格(上涨、下跌、负数、小数)

正常修改股票名字,价格上涨
cat quote.json | jq '.data.items[1].quote.name="HogwartsTesting"' | jq '.data.items[1].quote.percent=1.11' > mock1.json

 null值修改, 股票价格下跌:
cat quote.json | jq '.data.items[0].quote.name=null' | jq '.data.items[0].quote.percent="-4.4"' > mock2.json

价格为3位小数/负数:
cat quote.json | jq '.data.items[4].quote.current=251.687|.data.items[3].quote.current="-25"' > mock6.json

“ ” 空值修改
cat quote.json | jq '.data.items[3].quote.name=""' > mock4.json


3.针对股票列表页批量操作(列表页股票清空、剩1支、倍增千倍)

倍增:
cat mock.json | jq '.data.items+=.data.items' |jq '.data.items_size+=.data.items_size' > mock.json

剩一支:
cat stocktest.json | jq '.data.items=.data.items[0]' |jq '.data.items_size=1'>stocktest.json

清空:
cat quote.json | jq '.data.items=[]|.data.items_size=0' > mock5.json

1 Like

作业
测试名称长度

 cat stocklist2.json| jq '.data.items[1].quote.name="测试111111111111111111111111111111"' | jq '.data.items[2].quote.name=""' > stocklist.json
 cat stocklist2.json| jq '.data.items[1].quote.name="测试111111111111111111111111111111"' | jq '.data.items[2].quote.name=null' > stocklist.json

上涨下跌

cat stocklist2.json| jq '.data.items[1].quote.current+=100000' > stocklist.json
cat stocklist2.json| jq '.data.items[1].quote.current-=100000' > stocklist.json
cat stocklist2.json| jq '.data.items[1].quote.current=0.000000887665443' > stocklist.json

列表指批量变化

cat stocklist2.json| jq '.data.items_size=0' | jq '.data.items=[]'> stocklist.json
cat stocklist2.json| jq '.data.items_size=0' | jq '.data.items[0]'> stocklist.json
cat stocklist2.json| jq '.data.items_size*2' | jq '.data.items+=.data.items'> stocklist.json
关闭