Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
66352476cd |
64
includes/scraper.php
Normal file
64
includes/scraper.php
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
function getLeetCodeProfile($handle) {
|
||||||
|
$url = 'https://leetcode.com/graphql';
|
||||||
|
$query = '
|
||||||
|
query getUserProfile($username: String!) {
|
||||||
|
matchedUser(username: $username) {
|
||||||
|
username
|
||||||
|
submitStats: submitStatsGlobal {
|
||||||
|
acSubmissionNum {
|
||||||
|
difficulty
|
||||||
|
count
|
||||||
|
submissions
|
||||||
|
}
|
||||||
|
}
|
||||||
|
profile {
|
||||||
|
ranking
|
||||||
|
userAvatar
|
||||||
|
realName
|
||||||
|
}
|
||||||
|
languageProblemCount {
|
||||||
|
languageName
|
||||||
|
problemsSolved
|
||||||
|
}
|
||||||
|
recentAcSubmissionList {
|
||||||
|
id
|
||||||
|
title
|
||||||
|
titleSlug
|
||||||
|
timestamp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
';
|
||||||
|
|
||||||
|
$variables = ['username' => $handle];
|
||||||
|
$data = ['query' => $query, 'variables' => $variables];
|
||||||
|
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||||
|
'Content-Type: application/json',
|
||||||
|
'Content-Length: ' . strlen(json_encode($data))
|
||||||
|
]);
|
||||||
|
|
||||||
|
$result = curl_exec($ch);
|
||||||
|
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
|
||||||
|
if ($result === FALSE || $httpcode != 200) {
|
||||||
|
return ['error' => 'Failed to fetch data from LeetCode.'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$profileData = json_decode($result, true);
|
||||||
|
|
||||||
|
if (isset($profileData['errors']) || !isset($profileData['data']['matchedUser']) || $profileData['data']['matchedUser'] === null) {
|
||||||
|
return ['error' => 'User not found or API error.'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $profileData['data']['matchedUser'];
|
||||||
|
}
|
||||||
|
?>
|
||||||
193
index.php
193
index.php
@ -1,150 +1,85 @@
|
|||||||
<?php
|
<!DOCTYPE html>
|
||||||
declare(strict_types=1);
|
|
||||||
@ini_set('display_errors', '1');
|
|
||||||
@error_reporting(E_ALL);
|
|
||||||
@date_default_timezone_set('UTC');
|
|
||||||
|
|
||||||
$phpVersion = PHP_VERSION;
|
|
||||||
$now = date('Y-m-d H:i:s');
|
|
||||||
?>
|
|
||||||
<!doctype html>
|
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>New Style</title>
|
<title>CodeScore - Candidate Analytics</title>
|
||||||
<?php
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
// Read project preview data from environment
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
||||||
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
||||||
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
|
||||||
?>
|
|
||||||
<?php if ($projectDescription): ?>
|
|
||||||
<!-- Meta description -->
|
|
||||||
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
|
|
||||||
<!-- Open Graph meta tags -->
|
|
||||||
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
|
||||||
<!-- Twitter meta tags -->
|
|
||||||
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
|
||||||
<?php endif; ?>
|
|
||||||
<?php if ($projectImageUrl): ?>
|
|
||||||
<!-- Open Graph image -->
|
|
||||||
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
|
||||||
<!-- Twitter image -->
|
|
||||||
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
|
||||||
<?php endif; ?>
|
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
|
|
||||||
<style>
|
<style>
|
||||||
:root {
|
|
||||||
--bg-color-start: #6a11cb;
|
|
||||||
--bg-color-end: #2575fc;
|
|
||||||
--text-color: #ffffff;
|
|
||||||
--card-bg-color: rgba(255, 255, 255, 0.01);
|
|
||||||
--card-border-color: rgba(255, 255, 255, 0.1);
|
|
||||||
}
|
|
||||||
body {
|
body {
|
||||||
margin: 0;
|
|
||||||
font-family: 'Inter', sans-serif;
|
font-family: 'Inter', sans-serif;
|
||||||
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
|
background-color: #f8f9fa;
|
||||||
color: var(--text-color);
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
min-height: 100vh;
|
|
||||||
text-align: center;
|
|
||||||
overflow: hidden;
|
|
||||||
position: relative;
|
|
||||||
}
|
}
|
||||||
body::before {
|
.navbar {
|
||||||
content: '';
|
box-shadow: 0 2px 4px rgba(0,0,0,.05);
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
|
|
||||||
animation: bg-pan 20s linear infinite;
|
|
||||||
z-index: -1;
|
|
||||||
}
|
}
|
||||||
@keyframes bg-pan {
|
.hero {
|
||||||
0% { background-position: 0% 0%; }
|
background: linear-gradient(135deg, #0d6efd, #0d6efd20);
|
||||||
100% { background-position: 100% 100%; }
|
padding: 4rem 0;
|
||||||
}
|
color: white;
|
||||||
main {
|
|
||||||
padding: 2rem;
|
|
||||||
}
|
}
|
||||||
.card {
|
.card {
|
||||||
background: var(--card-bg-color);
|
transition: transform .2s;
|
||||||
border: 1px solid var(--card-border-color);
|
|
||||||
border-radius: 16px;
|
|
||||||
padding: 2rem;
|
|
||||||
backdrop-filter: blur(20px);
|
|
||||||
-webkit-backdrop-filter: blur(20px);
|
|
||||||
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
|
|
||||||
}
|
}
|
||||||
.loader {
|
.card:hover {
|
||||||
margin: 1.25rem auto 1.25rem;
|
transform: translateY(-5px);
|
||||||
width: 48px;
|
|
||||||
height: 48px;
|
|
||||||
border: 3px solid rgba(255, 255, 255, 0.25);
|
|
||||||
border-top-color: #fff;
|
|
||||||
border-radius: 50%;
|
|
||||||
animation: spin 1s linear infinite;
|
|
||||||
}
|
|
||||||
@keyframes spin {
|
|
||||||
from { transform: rotate(0deg); }
|
|
||||||
to { transform: rotate(360deg); }
|
|
||||||
}
|
|
||||||
.hint {
|
|
||||||
opacity: 0.9;
|
|
||||||
}
|
|
||||||
.sr-only {
|
|
||||||
position: absolute;
|
|
||||||
width: 1px; height: 1px;
|
|
||||||
padding: 0; margin: -1px;
|
|
||||||
overflow: hidden;
|
|
||||||
clip: rect(0, 0, 0, 0);
|
|
||||||
white-space: nowrap; border: 0;
|
|
||||||
}
|
|
||||||
h1 {
|
|
||||||
font-size: 3rem;
|
|
||||||
font-weight: 700;
|
|
||||||
margin: 0 0 1rem;
|
|
||||||
letter-spacing: -1px;
|
|
||||||
}
|
|
||||||
p {
|
|
||||||
margin: 0.5rem 0;
|
|
||||||
font-size: 1.1rem;
|
|
||||||
}
|
|
||||||
code {
|
|
||||||
background: rgba(0,0,0,0.2);
|
|
||||||
padding: 2px 6px;
|
|
||||||
border-radius: 4px;
|
|
||||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
||||||
}
|
|
||||||
footer {
|
|
||||||
position: absolute;
|
|
||||||
bottom: 1rem;
|
|
||||||
font-size: 0.8rem;
|
|
||||||
opacity: 0.7;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-light bg-white sticky-top">
|
||||||
|
<div class="container">
|
||||||
|
<a class="navbar-brand fw-bold" href="#">CodeScore</a>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
<div class="card">
|
<section class="hero text-center">
|
||||||
<h1>Analyzing your requirements and generating your website…</h1>
|
<div class="container">
|
||||||
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
|
<h1 class="display-4 fw-bold">Candidate Skill Analytics</h1>
|
||||||
<span class="sr-only">Loading…</span>
|
<p class="lead col-md-8 mx-auto">Aggregate and analyze developer scores from top coding platforms to find the best talent, faster.</p>
|
||||||
</div>
|
</div>
|
||||||
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
|
</section>
|
||||||
<p class="hint">This page will update automatically as the plan is implemented.</p>
|
|
||||||
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
|
<section class="py-5">
|
||||||
|
<div class="container">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-lg-8">
|
||||||
|
<div class="card shadow-sm">
|
||||||
|
<div class="card-body p-5">
|
||||||
|
<h2 class="card-title text-center mb-4">Find a Candidate Profile</h2>
|
||||||
|
<form action="profile.php" method="GET">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="handle" class="form-label">LeetCode Handle</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<span class="input-group-text"><i class="bi bi-person"></i></span>
|
||||||
|
<input type="text" class="form-control form-control-lg" id="handle" name="handle" placeholder="e.g., awesome_coder_123" required>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="d-grid">
|
||||||
|
<button type="submit" class="btn btn-primary btn-lg">Fetch Profile</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<div class="text-center mt-3">
|
||||||
|
<small class="text-muted">Support for other platforms coming soon!</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
</main>
|
</main>
|
||||||
<footer>
|
|
||||||
Page updated: <?= htmlspecialchars($now) ?> (UTC)
|
<footer class="text-center py-4 text-muted">
|
||||||
|
<div class="container">
|
||||||
|
<p>© <?php echo date("Y"); ?> CodeScore. All Rights Reserved.</p>
|
||||||
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
163
profile.php
Normal file
163
profile.php
Normal file
@ -0,0 +1,163 @@
|
|||||||
|
<?php
|
||||||
|
$handle = htmlspecialchars($_GET['handle'] ?? 'N/A');
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Profile: <?php echo $handle; ?> - CodeScore</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: 'Inter', sans-serif;
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
}
|
||||||
|
.navbar {
|
||||||
|
box-shadow: 0 2px 4px rgba(0,0,0,.05);
|
||||||
|
}
|
||||||
|
.stat-card {
|
||||||
|
border-left: 4px solid #0d6efd;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-light bg-white sticky-top">
|
||||||
|
<div class="container">
|
||||||
|
<a class="navbar-brand fw-bold" href="index.php">CodeScore</a>
|
||||||
|
<a href="index.php" class="btn btn-outline-primary">Back to Search</a>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<main class="container py-5">
|
||||||
|
<?php
|
||||||
|
require_once 'includes/scraper.php';
|
||||||
|
$profileData = getLeetCodeProfile($handle);
|
||||||
|
|
||||||
|
if (isset($profileData['error'])):
|
||||||
|
?>
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
<strong>Error:</strong> <?php echo htmlspecialchars($profileData['error']); ?>
|
||||||
|
<p>Please check the handle and try again. Note that the LeetCode API might be temporarily unavailable.</p>
|
||||||
|
</div>
|
||||||
|
<?php else:
|
||||||
|
// Process data
|
||||||
|
$totalSolved = 0;
|
||||||
|
$easySolved = 0;
|
||||||
|
$mediumSolved = 0;
|
||||||
|
$hardSolved = 0;
|
||||||
|
if (isset($profileData['submitStats']['acSubmissionNum'])) {
|
||||||
|
foreach ($profileData['submitStats']['acSubmissionNum'] as $stat) {
|
||||||
|
if ($stat['difficulty'] == 'All') {
|
||||||
|
$totalSolved = $stat['count'];
|
||||||
|
} else if ($stat['difficulty'] == 'Easy') {
|
||||||
|
$easySolved = $stat['count'];
|
||||||
|
} else if ($stat['difficulty'] == 'Medium') {
|
||||||
|
$mediumSolved = $stat['count'];
|
||||||
|
} else if ($stat['difficulty'] == 'Hard') {
|
||||||
|
$hardSolved = $stat['count'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<div class="p-4 p-md-5 mb-4 rounded text-bg-dark d-flex align-items-center">
|
||||||
|
<?php if (!empty($profileData['profile']['userAvatar'])): ?>
|
||||||
|
<img src="<?php echo htmlspecialchars($profileData['profile']['userAvatar']); ?>" alt="User Avatar" class="rounded-circle me-4" width="80" height="80">
|
||||||
|
<?php endif; ?>
|
||||||
|
<div>
|
||||||
|
<h1 class="display-4 fst-italic"><?php echo htmlspecialchars($profileData['profile']['realName']); ?></h1>
|
||||||
|
<p class="lead my-1">@<?php echo htmlspecialchars($profileData['username']); ?> on LeetCode</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row g-4 mb-4">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="card stat-card shadow-sm h-100">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title text-primary">Contest Rating</h5>
|
||||||
|
<p class="card-text display-4 fw-bold"><?php echo number_format($profileData['profile']['ranking']); ?></p>
|
||||||
|
<small class="text-muted">Global Rank</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="card stat-card shadow-sm h-100" style="border-left-color: #198754;">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title text-success">Problems Solved</h5>
|
||||||
|
<p class="card-text display-4 fw-bold"><?php echo $totalSolved; ?></p>
|
||||||
|
<small class="text-muted"><?php echo "$easySolved Easy, $mediumSolved Medium, $hardSolved Hard"; ?></small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="card stat-card shadow-sm h-100" style="border-left-color: #ffc107;">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title text-warning">Recent Activity</h5>
|
||||||
|
<p class="card-text display-4 fw-bold"><?php echo count($profileData['recentAcSubmissionList']); ?></p>
|
||||||
|
<small class="text-muted">Accepted submissions in last 20 entries</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row g-4">
|
||||||
|
<div class="col-lg-6">
|
||||||
|
<div class="card shadow-sm h-100">
|
||||||
|
<div class="card-header">
|
||||||
|
<h4 class="my-0 fw-normal">Recent Submissions</h4>
|
||||||
|
</div>
|
||||||
|
<ul class="list-group list-group-flush">
|
||||||
|
<?php if (!empty($profileData['recentAcSubmissionList'])): ?>
|
||||||
|
<?php foreach (array_slice($profileData['recentAcSubmissionList'], 0, 5) as $submission): ?>
|
||||||
|
<li class="list-group-item d-flex justify-content-between align-items-center">
|
||||||
|
<a href="https://leetcode.com/problems/<?php echo $submission['titleSlug']; ?>" target="_blank" rel="noopener noreferrer">
|
||||||
|
<?php echo htmlspecialchars($submission['title']); ?>
|
||||||
|
</a>
|
||||||
|
<small class="text-muted"><?php echo date('M d, Y', $submission['timestamp']); ?></small>
|
||||||
|
</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php else: ?>
|
||||||
|
<li class="list-group-item">No recent submissions found.</li>
|
||||||
|
<?php endif; ?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-6">
|
||||||
|
<div class="card shadow-sm h-100">
|
||||||
|
<div class="card-header">
|
||||||
|
<h4 class="my-0 fw-normal">Languages</h4>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<?php
|
||||||
|
if (!empty($profileData['languageProblemCount'])) {
|
||||||
|
usort($profileData['languageProblemCount'], function($a, $b) {
|
||||||
|
return $b['problemsSolved'] <=> $a['problemsSolved'];
|
||||||
|
});
|
||||||
|
foreach ($profileData['languageProblemCount'] as $lang) {
|
||||||
|
echo '<span class="badge bg-secondary m-1 p-2">'
|
||||||
|
. htmlspecialchars($lang['languageName'])
|
||||||
|
. ' <span class="badge bg-light text-dark ms-1">' . $lang['problemsSolved'] . '</span></span>';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo '<p>No language stats found.</p>';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer class="text-center py-4 text-muted">
|
||||||
|
<div class="container">
|
||||||
|
<p>© <?php echo date("Y"); ?> CodeScore. All Rights Reserved.</p>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
x
Reference in New Issue
Block a user