Skip to content

Instantly share code, notes, and snippets.

@nguyenphucbao68
Last active April 1, 2017 11:05
Show Gist options
  • Save nguyenphucbao68/b518607bd591390aa7d693c26a9c7d46 to your computer and use it in GitHub Desktop.
Save nguyenphucbao68/b518607bd591390aa7d693c26a9c7d46 to your computer and use it in GitHub Desktop.
Code Ranking Group
; #FUNCTION# ====================================================================================================================
; Name ..........: _GetPost2
; Description ...: Hàm chạy Add User và Hệ thống Ranking
; Syntax ........: _GetPost2($access_token, ByRef $link, $LimitTime)
; Parameters ....: $access_token - Access Token.
; ByRef $link - Link Json (Sẽ thay đổi liên tục trong quá trình gọi đệ quy).
; $LimitTime - Thời gian kiểm soát (vd : 1 ngày, 1 tuần, 1 tháng,...) - đổi sang giây.
; Return values .: Success : Trả về 1, và lấy giá trị trong mảng $Array2d 2 chiều
; Failure : @error set về 0
; Author ........: Trojan Nguyen
; ===============================================================================================================================
Func _GetPost2($access_token,ByRef $link, $LimitTime)
Local $JsonObj, $i, $point, $actor_id, $post_id, $sharecount, $linkReactions, $j, $tam, $linkCMT, $updated_time
$JsonObj = Json_Decode(_INetGetSource($link))
;~ If @error then Return SetError(1,0,0)
$i = 0
While 1
$point = 0
$updated_time = Json_Get($JsonObj, '["data"][' & $i & ']["updated_time"]')
If @error then ExitLoop
If _FOrmatTime($updated_time)<$LimitTime Then ExitLoop
$actor_id = Json_Get($JsonObj, '["data"][' & $i & ']["from"]["id"]')
If @error then ExitLoop
$User_Name = Json_Get($JsonObj, '["data"][' & $i & ']["from"]["name"]')
If @error then ExitLoop
$point += 3
$post_id = Json_Get($JsonObj, '["data"][' & $i & ']["id"]')
If @error then ExitLoop
ConsoleWrite($post_id&@CRLF)
$sharecount = _GetShare($post_id, $access_token)
If $sharecount <> False then $point += $sharecount*1
$linkReactions = "https://graph.facebook.com/v2.8/"&$post_id&"/reactions?limit=1000&access_token="&$access_token
Global $Array = Json_ObjCreate()
$check = _GetReactions($linkReactions)
If $check=false Then
Json_Put($Array2d, "."&$actor_id&"[id]", $actor_id)
Json_Put($Array2d, "."&$actor_id&"[name]", $User_Name)
Json_Put($Array2d, "."&$actor_id&"[points]", Json_Get($Array2d, "."&$actor_id&"[points]")+1)
Json_Put($Array2d, "."&$actor_id&"[totalPosts]", Json_Get($Array2d, "."&$actor_id&"[totalPosts]"))
Else
$point += $check*1 ; Tăng điểm cho người đăng bài dựa trên số lượng like
EndIf
For $tam in $Array
$id = Json_Get($Array, "."&$tam&"[id]")
$name = Json_Get($Array, "."&$tam&"[name]")
Json_Put($Array2d, "."&$id&"[id]", $id)
Json_Put($Array2d, "."&$id&"[name]", $name)
Json_Put($Array2d, "."&$id&"[points]", Json_Get($Array2d, "."&$id&"[points]")+1)
Json_Put($Array2d, "."&$id&"[totalPosts]", Json_Get($Array2d, "."&$id&"[totalPosts]"))
Next
$linkCMT = "https://graph.facebook.com/v2.8/"&$post_id&"?limit=1000&fields=comments&access_token="&$access_token
Global $ArrayCMT = Json_ObjCreate()
$check = _GetCMT($linkCMT)
If $check=false Then
Json_Put($Array2d, "."&$actor_id&"[id]", $actor_id)
Json_Put($Array2d, "."&$actor_id&"[name]", $User_Name)
Json_Put($Array2d, "."&$actor_id&"[points]", Json_Get($Array2d, "."&$actor_id&"[points]")+2)
Json_Put($Array2d, "."&$actor_id&"[totalPosts]", Json_Get($Array2d, "."&$actor_id&"[totalPosts]"))
Else
$point += $check*2 ;Tăng điểm cho người đăng bài dựa trên số lượng cmt
EndIf
For $tam in $ArrayCMT
$id = Json_Get($ArrayCMT, "."&$tam&"[id]")
$name = Json_Get($ArrayCMT, "."&$tam&"[name]")
Json_Put($Array2d, "."&$id&"[id]", $id)
Json_Put($Array2d, "."&$id&"[name]", $name)
Json_Put($Array2d, "."&$id&"[points]", Json_Get($Array2d, "."&$id&"[points]")+1)
Json_Put($Array2d, "."&$actor_id&"[totalPosts]", Json_Get($Array2d, "."&$actor_id&"[totalPosts]"))
Next
Json_Put($Array2d, "."&$actor_id&"[id]", $actor_id)
Json_Put($Array2d, "."&$actor_id&"[totalPosts]", Json_Get($Array2d, "."&$actor_id&"[totalPosts]")+1)
Json_Put($Array2d, "."&$actor_id&"[name]", $User_Name)
Json_Put($Array2d, "."&$actor_id&"[points]", Json_Get($Array2d, "."&$actor_id&"[points]")+$point)
$updated_time = Json_Get($JsonObj, '["data"][' & $i & ']["updated_time"]') ; Lấy Update time để kiểm tra Limit Time
$i += 1
WEnd
If _FOrmatTime($updated_time)<$LimitTime Then
Return 1
Else
$updated_time = Json_Get($JsonObj, '["data"][' & $i-1 & ']["updated_time"]')
If @error then Return SetError(1,0,0)
If $updated_time<=$LimitTime Then
Return 1
Else
$link = Json_Get($JsonObj, '["paging"]["next"]'); Lấy link kế tiếp của api để get tiếp
If $link<>"" then
_GetPost2($access_token, $link, $LimitTime) ; Gọi đệ quy để cộng dồn
Else
Return 1
EndIf
EndIf
EndIf
EndFunc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment