Skip to content

Commit

Permalink
Merge branch 'feat/fediseer'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jelloeater committed Oct 31, 2023
2 parents 181fd82 + b7d5dff commit 929d21a
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 37 deletions.
11 changes: 11 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]

[dev-packages]

[requires]
python_version = "3.10"
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
- Powers https://lemmy-status.org/
- If you have questions or problems deploying feel free to contact me via links in my GH Profile

> ==FIXME==
>
> **Well the orig API backend is only returning like 4 results... so Imma just gonna hit up db0, cause he's a cool dude ;-)**
```mermaid
flowchart
docker_compose
Expand Down
2 changes: 1 addition & 1 deletion fedi_gatus/api_server/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async def root():
async def healthcheck():
pass
# TODO Write health check endpoint

#TODO Add top instance query function and JSON return

class Server:
port = 8888
Expand Down
14 changes: 11 additions & 3 deletions fedi_gatus/config_gen/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,17 @@ def generate_full_config():

def generate_top_instances():
logging.info("Get top instances")
d = db.DbAccess().get_top_lemmy_instances()
from pythonseer import Fediseer
f = Fediseer()
fediseer_data = f.whitelist.get(guarantors=1, endorsements=3)['instances']

d = []
for i in fediseer_data:
d.append(i['domain'])

# d = db.DbAccess().get_top_instances() # FIXME Backend is only returning a very small set of data... funnnnnn
instances = []
for i in d: # TODO not in order by user count
url = "https://" + i.domain
instances.append({"name": f"{i.domain}", "url": url})
url = "https://" + i
instances.append({"name": f"{i}", "url": url})
return instances
4 changes: 2 additions & 2 deletions fedi_gatus/shared/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ def __init__(self, *args, **kwargs):
def get_single_record(self) -> dict:
return self.select().get()

def get_top_lemmy_instances(self, count=25) -> list[Model]:
def get_top_instances(self, software_name='Lemmy', count=25) -> list[Model]:
# TODO Add env var for count

if not os.getenv("TEST_MODE"):
count = int(os.getenv("NUMBER_OF_SERVERS"))
logging.info("Number of Rows:" + str(DbAccess.select().count()))
d = (
DbAccess.select()
.where(DbAccess.software_name == "Lemmy")
.where(DbAccess.software_name == software_name)
.order_by(DbAccess.stats_monthly_active_users.desc())
.limit(count)
)
Expand Down
3 changes: 1 addition & 2 deletions fedi_gatus/updater/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
import requests

from fedi_gatus.shared import db

from pythonseer import Fediseer

class Worker:
raw_data = None

def get_raw_data(self):
data = []

rest_data = requests.get(url="https://api.fedidb.org/v1/servers/", params={"limit": 40}, timeout=3).json()
for i in rest_data["data"]:
data.append(i)
Expand Down
70 changes: 44 additions & 26 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ fastapi = "0.96.0"
uvicorn ={version="0.22.0", extras = ["standard"]}
munch = "^4.0.0"
psycopg2-binary = "^2.9.7"
pythonseer = {git = "https://github.com/jelloeater/pythonseer"}


[tool.pytest.ini_options]
pythonpath = ["."]
Expand Down
6 changes: 3 additions & 3 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import os

os.environ["SQL_LITE"] = "1"
os.environ["TEST_MODE"] = "1"
# os.environ["TEST_MODE"] = "1"


class TestData:
Expand Down Expand Up @@ -47,7 +47,7 @@ def test_db_get(cls):
@classmethod
def test_db_get_top(cls):
d = db.DbAccess()
r = d.get_top_lemmy_instances()
r = d.get_top_instances()
assert r is not None

@classmethod
Expand All @@ -58,7 +58,7 @@ def test_db_full_load(cls):
d = db.DbAccess()
d.drop_table() # Clear table
d.create_table()
r = d.get_top_lemmy_instances()
r = d.get_top_instances()
end = time.time()
logging.debug(end - start)
assert r is not None
Expand Down

0 comments on commit 929d21a

Please sign in to comment.