Skip to content

Instantly share code, notes, and snippets.

@ogarcia
Last active November 27, 2016 12:57
Show Gist options
  • Save ogarcia/19d5bfb6c73f93bb37be083151b7b7a7 to your computer and use it in GitHub Desktop.
Save ogarcia/19d5bfb6c73f93bb37be083151b7b7a7 to your computer and use it in GitHub Desktop.
Get full list of synced tier 1 Arch Linux mirrors
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2016 Óscar García Amor <ogarcia@connectical.com>
#
# Distributed under terms of the GNU GPLv3 license.
from time import strftime
import requests
def get_mirrors(mirrors_url):
request = requests.get(mirrors_url)
full_mirror_list = request.json()
# Pick only mirrors in sync and with http or https protocol
mirror_list = [mirror for mirror in full_mirror_list['urls'] if mirror['completion_pct'] == 1 and mirror['protocol'] != 'rsync']
# Return list sorted by score
return sorted(mirror_list, key=lambda mirror: mirror['score'])
if __name__ == '__main__':
mirrors_url = 'https://www.archlinux.org/mirrors/status/tier/1/json/'
mirrors = get_mirrors(mirrors_url)
print ('##\n## Arch Linux repository mirrorlist')
print ('## Sorted by mirror score from mirror tier 1 status page')
print ('## Generated on {}\n##\n'.format(strftime("%Y-%m-%d")))
for mirror in mirrors:
print ('## Score: {score:.2f}, {country}'.format(**mirror))
print ('Server = {url}$repo/os/$arch'.format(**mirror))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment