Skip to content

Commit

Permalink
+Seeding count
Browse files Browse the repository at this point in the history
  • Loading branch information
skidoodle committed Oct 10, 2024
1 parent c6ac549 commit 9acfc49
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 38 deletions.
11 changes: 0 additions & 11 deletions data/data.json

This file was deleted.

35 changes: 21 additions & 14 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,17 @@ <h2 class="text-2xl mb-6 font-semibold" id="modal-profile-name">
)

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)
}
Expand Down Expand Up @@ -201,7 +202,7 @@ <h2 class="text-2xl font-semibold mb-4"><i class='bx bxs-user text-2xl mr-2'></i
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)
)
Expand All @@ -211,9 +212,9 @@ <h2 class="text-2xl font-semibold mb-4"><i class='bx bxs-user text-2xl mr-2'></i
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,
Expand Down Expand Up @@ -248,6 +249,12 @@ <h2 class="text-2xl font-semibold mb-4"><i class='bx bxs-user text-2xl mr-2'></i
borderColor: 'rgba(153, 102, 255, 1)',
fill: false,
},
{
label: 'Seeding Count',
data: seedingCount,
borderColor: 'rgba(255, 159, 64, 1)',
fill: false,
},
],
}

Expand Down
40 changes: 30 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"log"
"net/http"
"os"
"regexp"
"strconv"
"strings"
"time"

"github.com/PuerkitoBio/goquery"
Expand All @@ -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() {
Expand Down Expand Up @@ -93,15 +97,31 @@ 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:":
profile.CurrentUpload = value
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)
}
})

Expand Down
4 changes: 1 addition & 3 deletions profiles.json
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
{
"displayName": "userId"
}
{}

0 comments on commit 9acfc49

Please sign in to comment.