#!/usr/bin/env python
# -*- coding: utf-8 -*-

from pyeupi import PyEUPI
import json
import argparse


authkey = '5246b7d2cf2d36e49f7378c5dbaeb9f70d7e2ffe8ecaacdb0283edee898d4f58'

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Query Phishing Initiative service.')
    parser.add_argument("--url", default='https://fr.dev.phishing-initiative.net', help='URL where the service is running (no path).')
    g = parser.add_mutually_exclusive_group(required=True)
    g.add_argument('-u', '--urls', help='Query a URL. Integer means URL ID, a string search the URL in the database. If 0, it returns the first page of urls.')
    g.add_argument('-s', '--submissions', type=int, help='Query your submissions (if 0, returns the first page of submissions)')
    g.add_argument('-p', '--post', help='URL to submit')
    args = parser.parse_args()

    p = PyEUPI(authkey, args.url)
    if args.urls is not None:
        try:
            uid = int(args.urls)
            if args.urls == 0:
                response = p.get_url()
            else:
                response = p.get_url(uid)
        except:
            response = p.search_url(args.urls)

    elif args.submissions is not None:
        if args.submissions == 0:
            response = p.get_submission()
        else:
            response = p.get_submission(args.submissions)

    elif args.post is not None:
        response = p.post_submission(args.post)

    print json.dumps(response)
