Created
June 27, 2016 09:15
-
-
Save selfboot/0b166f48c959893f2ebab2d345bec6c4 to your computer and use it in GitHub Desktop.
Simple website speed test tools.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| # @Last Modified time: 2016-06-27 17:03:42 | |
| import requests | |
| import os | |
| def get_speed_test(src_path, result_path, timeout=10): | |
| all_sites = _get_sites_(src_path) | |
| results = [] | |
| for site in all_sites: | |
| print "Test site: {:s}".format(site) | |
| try: | |
| t = requests.get(site, timeout=timeout).elapsed.total_seconds() | |
| except: | |
| t = 9999 | |
| results.append(t) | |
| print "Speed test finished! Write results to %s" % result_path | |
| with open(result_path, 'w') as f: | |
| map(lambda x: f.write("{:<30s} - {:2.5f}\n".format(x[0], x[1])), zip(all_sites, results)) | |
| def _get_sites_(file_path): | |
| if not os.path.isfile(file_path): | |
| return None | |
| sites = [] | |
| with open(file_path, 'r') as f: | |
| for site in f.readlines(): | |
| sites.append(site.strip()) | |
| return sites |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment