这是一个批量统计国内版 LeetCode 做题量的工具,写这个小工具的起因是我们实验室准备每周统计大家 leetcode 的做题量,我们实验室十几个人,如果一人一个人看,太费时间了,作为高效程序员这不是我们做事的风格,于此就有了这个小工具。对于平常的事务我一贯对待的风格是:能规范化的尽量使其流程化,能流程化的尽量使其自动化。追逐效率工具能解放我们更多的时间,这没什么可说的。
脚本代码
1#!/bin/bash
2
3payload_pre='{
4 "operationName": "userPublicProfile",
5 "variables": {
6 "userSlug": "'
7payload_post='"
8 },
9 "query": "query userPublicProfile($userSlug: String!) {\n userProfilePublicProfile(userSlug: $userSlug) {\n username\n submissionProgress {\n totalSubmissions\n waSubmissions\n acSubmissions\n reSubmissions\n otherSubmissions\n acTotal\n questionTotal\n __typename\n }\n }\n}\n"
10}'
11
12# 获取信息的leetcode用户
13# 两数组元素需保持相同, shell数组格式: arr=( "a" "b" "c"),三个元素的数组arr
14account_arr=( "hun-tun-5" "mrlin-rh" ) # 个人主页用户名 https://leetcode-cn.com/u/freezer/
15name_arr=( "张三" "李四" )
16
17# 时间
18date
19
20#${#array[@]}获取数组长度
21for (( i=0;i<${#account_arr[@]};i++ )) do
22 account="${account_arr[i]}"
23 ret=`curl -s -L -X POST 'https://leetcode-cn.com/graphql/' -H 'Content-Type: application/json' --data "$payload_pre$account$payload_post"`
24 count=`echo $ret | grep -Eo '"acTotal":\d+' | grep -Eo '\d+'`
25 name="${name_arr[i]}"
26 echo "$name,$count"
27done
使用方法
将脚本复制到文件leetcodeutil.sh
,直接运行脚本,无需参数。
1sh ./leetcodeutil.sh
2或
3bash ./leetcodeutil.sh
执行效果: