<reponame>karantan/singer-playground<gh_stars>1-10
from datetime import datetime
from datetime import timezone

import singer
import urllib.request


def my_ip():
    now = datetime.now(timezone.utc).isoformat()
    schema = {
        'properties':   {
            'ip': {'type': 'string'},
            'timestamp': {'type': 'string', 'format': 'date-time'},
        },
    }

    with urllib.request.urlopen('http://icanhazip.com') as response:
        ip = response.read().decode('utf-8').strip()
        singer.write_schema('my_ip', schema, 'timestamp')
        singer.write_records('my_ip', [{'timestamp': now, 'ip': ip}])


if __name__ == "__main__":
    my_ip()

from datetime import datetime
from datetime import timezone

import singer
import urllib.request


def my_ip():
    now = datetime.now(timezone.utc).isoformat()
    schema = {
        'properties':   {
            'ip': {'type': 'string'},
            'timestamp': {'type': 'string', 'format': 'date-time'},
        },
    }

    with urllib.request.urlopen('http://icanhazip.com') as response:
        ip = response.read().decode('utf-8').strip()
        singer.write_schema('my_ip', schema, 'timestamp')
        singer.write_records('my_ip', [{'timestamp': now, 'ip': ip}])


if __name__ == "__main__":
    my_ip()