Skip to content

Instantly share code, notes, and snippets.

Created Jan 18, 2019

What would you like to do?
python: erlojua interneteko web orri batekin zinkronizatzeko script-a
# -*- coding: utf-8 -*-
import pycurl
from io import BytesIO
import re
from subprocess import Popen, PIPE
url = ''
headers = BytesIO()
buffer = BytesIO()
c = pycurl.Curl()
c.setopt(c.URL, url)
c.setopt(c.HEADER, 1)
c.setopt(c.NOBODY, 1) # header only, no body
c.setopt(c.HEADERFUNCTION, headers.write)
c.setopt(c.WRITEDATA, buffer)
headers = headers.getvalue()
headers = headers.decode("utf-8")
headers = re.split(r'\r\n', headers)
date = None
for i in headers:
if('^Date', i)):
date = i
if date:
date = re.sub(r'^Date:\s+', '', date)
Popen('/bin/date -s "'+date+'"', shell=True, stdout=PIPE)
print('date-sync: ERROR: NO TIME')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.