Re: QQGroup Analyzer

From NAT, 5 Years ago, written in Bash, viewed 790 times. This paste is a reply to QQGroup Analyzer from NAT - view diff
URL https://code.nat.moe/view/8a544142 Embed
Download Paste or View Raw
  1. #!/bin/bash
  2.  
  3. bkn=""
  4. COOKIE="Cookie: p_skey=...; p_uin=...; pt4_token=...; ts_last=...; ts_refer=...; ts_uid=...; RK=...; pgv_info=ssid=...; pgv_pvid=...; ......"
  5.  
  6. # You can get those using brup :)
  7.  
  8. USERS_JSON_URL="http://qun.qq.com/cgi-bin/qun_mgr/search_group_members"
  9. USERS_GET_PAYLOAD="gc=_GID_&st=0&end=1000&sort=0&bkn=$bkn"
  10.  
  11. GLIST_JSON_URL="http://qun.qq.com/cgi-bin/qun_mgr/get_group_list"
  12. GLIST_GET_PAYLOAD="bkn=$bkn"
  13.  
  14. # usage: getUsersList <gid>
  15. function getUsersList {
  16.         curl $USERS_JSON_URL --data "$(echo $USERS_GET_PAYLOAD | sed -e "s/_GID_/$1/")" -H "$COOKIE" 2> /dev/null | sed -e 's/{"card":/§{"card":/g'|tr '§' '\n'|awk -F\" '{print $33 "|" $4 "|" $22 }' | sed -e 's/|:/\|/g; s/}\,//g; s/://g; s/}\],//g; 1d;'
  17. }
  18.  
  19. function getGroupList {
  20.         curl $GLIST_JSON_URL --data $GLIST_GET_PAYLOAD -H "$COOKIE" 2> /dev/null | sed 's/"gc"/§"gc"/g' | tr '§' '\n' | awk -F':' '{print $2 "|" $3}' | sed -e 's/,"gn"//g; s/","owner"//g; s/"//g; 1d;'
  21. }
  22.  
  23. function getAllUsers {
  24.         getGroupList > groups.txt
  25.         local groups=$(cat groups.txt)
  26.         for group in $groups
  27.         do
  28.                 local gid=$(echo $group|awk -F"|" '{print $1}')
  29.                 echo -n "[$(date)] Getting $group... "
  30.                 getUsersList $group > group-$gid.txt
  31.                 echo "done"
  32.                 sleep 1
  33.         done
  34. }
  35.  
  36. function getUsersListFromList {
  37.         cat group-*.txt | awk -F"|" '{print $1}' | sort | uniq -d
  38. }
  39.  
  40.  
  41. # usage: findJoinedGroupByID <uid>
  42. function findJoinedGroupByID {
  43.         grep -lir "$1" . | grep group- | awk -F"group-|.txt" '{print $2}'
  44. }
  45.  
  46. function getGroupNameByID {
  47.         cat groups.txt | grep $1 | awk -F"|" '{print $2}' | sed -e 's/&nbsp;/ /g;'
  48. }
  49.  
  50. # usage: ListJoinedGroupByID [uid]
  51. function ListJoinedGroupByID {
  52.         local users=$(getUsersListFromList)
  53.         let thread=0
  54.         for user in $users
  55.         do
  56.                 [[ -z $1 || $1 == $user ]] && {
  57.                         echo "[$(date)] Progressing $user..."
  58.                         echo "User: $(getUsernameByID $user) ($user)" > user-$user.txt
  59.                         echo "-------------------------------------------------------------------------------" >> user-$user.txt
  60.                         local this_joined=$(findJoinedGroupByID $user)
  61.                         for this_group in $this_joined
  62.                         do
  63.                                 echo "$(getGroupNameByID $this_group) ($this_group) as $(getUsernameInGroupByID $this_group $user)" >> user-$user.txt
  64.                         done
  65.                         echo "-------------------------------------------------------------------------------" >> user-$user.txt
  66.                         echo >> user-$user.txt
  67.                         [[ $MAX_THREAD_GENLIST == $thread ]] && wait && thread=0                       
  68.                         let thread++
  69.                 } &
  70.         done
  71.         [[ -z $1 ]] && cat user-*.txt || cat user-$1.txt
  72. }
  73.  
  74. function getUsernameByID {
  75.         cat group-*.txt | grep $1 | tail -n1 | awk -F "|" '{print $3}' | sed -e 's/&nbsp;/ /g;'
  76. }
  77.  
  78. function getUsernameInGroupByID {
  79.         local name=$(cat group-$1.txt | grep $2 | awk -F "|" '{print $2}')
  80.         [[ -z $name ]] && name=$(cat group-$1.txt | grep $2 | awk -F "|" '{print $3}')
  81.         echo $name | sed -e 's/&nbsp;/ /g;'
  82. }
  83.  
  84. function showCommonGroups {
  85.         rm common.txt 2> /dev/null
  86.         for user in $(ls user-*.txt)
  87.         do
  88.                 local this_uid=$(echo $user | awk -F"user-|.txt" '{print $2}')
  89.                 echo $(getUsernameByID $this_uid) $this_uid: $(cat $user | wc -l | tr -d ' ') >> common.txt
  90.         done
  91.         cat common.txt | sort -k2nr -t":"
  92. }
  93.  
  94. $*
  95.  

Reply to "Re: QQGroup Analyzer"

Here you can reply to the paste above

captcha