+Seeding count

This commit is contained in:
skidoodle 2024-10-10 18:35:02 +02:00
parent c6ac549281
commit 9acfc490f0
Signed by: albert
GPG key ID: A06E3070D7D55BF2
4 changed files with 52 additions and 38 deletions

View file

@ -1,11 +0,0 @@
[
{
"owner": "displayName",
"timestamp": "2024-10-10T17:30:21.0999256+02:00",
"rank": "",
"upload": "",
"current_upload": "",
"current_download": "",
"points": ""
}
]

View file

@ -151,16 +151,17 @@
)
profileCard.innerHTML = `
<h2 class="text-2xl font-semibold mb-4"><i class='bx bxs-user text-2xl mr-2'></i>${owner}</h2>
<div class="space-y-2">
<p><i class='bx bx-trophy mr-2'></i> Rank: ${latestRecord.rank}</p>
<p><i class='bx bx-cloud-upload mr-2'></i> Upload: ${latestRecord.upload}</p>
<p><i class='bx bx-upload mr-2'></i> Current Upload: ${latestRecord.current_upload}</p>
<p><i class='bx bx-download mr-2'></i> Current Download: ${latestRecord.current_download}</p>
<p><i class='bx bx-coin mr-2'></i> Points: ${latestRecord.points}</p>
</div>
<button class="mt-6 px-4 py-2 text-white rounded" onclick="showHistory('${owner}', event)">View History</button>
`
<h2 class="text-2xl font-semibold mb-4"><i class='bx bxs-user text-2xl mr-2'></i>${owner}</h2>
<div class="space-y-2">
<p><i class='bx bx-trophy mr-2'></i> Rank: ${latestRecord.rank}</p>
<p><i class='bx bx-cloud-upload mr-2'></i> Upload: ${latestRecord.upload}</p>
<p><i class='bx bx-upload mr-2'></i> Current Upload: ${latestRecord.current_upload}</p>
<p><i class='bx bx-download mr-2'></i> Current Download: ${latestRecord.current_download}</p>
<p><i class='bx bx-coin mr-2'></i> Points: ${latestRecord.points}</p>
<p><i class='bx bx-folder mr-2'></i> Seeding Count: ${latestRecord.seeding_count}</p>
</div>
<button class="mt-6 px-4 py-2 text-white rounded" onclick="showHistory('${owner}', event)">View History</button>
`
profilesDiv.appendChild(profileCard)
}
@ -201,7 +202,7 @@
const labels = profileHistory.map(record =>
new Date(record.timestamp).toLocaleDateString()
)
const rankData = profileHistory.map(record => parseFloat(record.rank))
const rankData = profileHistory.map(record => record.rank)
const uploadData = profileHistory.map(record =>
parseStorageValue(record.upload)
)
@ -211,9 +212,9 @@
const downloadData = profileHistory.map(record =>
parseSpeedValue(record.current_download)
)
const pointsData = profileHistory.map(record =>
parseFloat(record.points)
)
const pointsData = profileHistory.map(record => record.points)
const seedingCount = profileHistory.map(record => record.seeding_count)
const chartData = {
labels: labels,
@ -248,6 +249,12 @@
borderColor: 'rgba(153, 102, 255, 1)',
fill: false,
},
{
label: 'Seeding Count',
data: seedingCount,
borderColor: 'rgba(255, 159, 64, 1)',
fill: false,
},
],
}

40
main.go
View file

@ -7,6 +7,9 @@ import (
"log"
"net/http"
"os"
"regexp"
"strconv"
"strings"
"time"
"github.com/PuerkitoBio/goquery"
@ -16,21 +19,22 @@ import (
type ProfileData struct {
Owner string `json:"owner"`
Timestamp time.Time `json:"timestamp"`
Rank string `json:"rank"`
Rank int `json:"rank"`
Upload string `json:"upload"`
CurrentUpload string `json:"current_upload"`
CurrentDownload string `json:"current_download"`
Points string `json:"points"`
Points int `json:"points"`
SeedingCount int `json:"seeding_count"`
}
var (
profiles = map[string]string{}
jsonFile = "./data/data.json"
profiles = map[string]string{}
jsonFile = "./data/data.json"
profilesFile = "profiles.json"
baseUrl = "https://ncore.pro/profile.php?id="
nick string
pass string
client *http.Client
baseUrl = "https://ncore.pro/profile.php?id="
nick string
pass string
client *http.Client
)
func init() {
@ -93,7 +97,11 @@ func fetchProfile(url string, displayName string) (*ProfileData, error) {
switch label {
case "Helyezés:":
profile.Rank = value
value = strings.TrimSuffix(value, ".")
rank, err := strconv.Atoi(value)
if err == nil {
profile.Rank = rank
}
case "Feltöltés:":
profile.Upload = value
case "Aktuális feltöltés:":
@ -101,7 +109,19 @@ func fetchProfile(url string, displayName string) (*ProfileData, error) {
case "Aktuális letöltés:":
profile.CurrentDownload = value
case "Pontok száma:":
profile.Points = value
points, err := strconv.Atoi(value)
if err == nil {
profile.Points = points
}
}
})
doc.Find(".lista_mini_fej").Each(func(i int, s *goquery.Selection) {
text := s.Text()
re := regexp.MustCompile(`\((\d+)\)`)
matches := re.FindStringSubmatch(text)
if len(matches) > 1 {
fmt.Sscanf(matches[1], "%d", &profile.SeedingCount)
}
})

View file

@ -1,3 +1 @@
{
"displayName": "userId"
}
{}