1
0
Fork 0
mirror of https://github.com/Findus23/RadioStats.git synced 2024-09-19 16:03:48 +02:00
RadioStats/sitemap.py

23 lines
884 B
Python
Raw Normal View History

2018-08-27 20:21:09 +02:00
from peewee import SQL, fn
2018-08-27 20:29:18 +02:00
from models import Channel, Play, Song
xml = """<?xml version="1.0" encoding="UTF-8"?>
2018-08-27 20:21:09 +02:00
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
"""
for channel in Channel.select().where(Channel.has_data == 1):
2018-08-27 20:29:18 +02:00
xml += "<url><loc>https://radiostats.lw1.at/{channel}</loc></url>".format(channel=channel.shortname)
2018-08-27 20:21:09 +02:00
get = Play.select(Play.song, Song.id, fn.Count(SQL('*')).alias("count")) \
.join(Channel).switch(Play).join(Song) \
.where((Song.show == 0) & (Channel.shortname == channel.shortname)) \
.group_by(Play.song).order_by(SQL('count').desc()).limit(500)
for i in get:
song = i.song.id
2018-08-27 20:29:18 +02:00
xml += "<url><loc>https://radiostats.lw1.at/{channel}/song/{songid}</loc></url>".format(channel=channel.shortname, songid=song)
2018-08-27 20:21:09 +02:00
xml += "</urlset>"
with open('sitemap.xml', 'w') as file:
file.write(xml)