# coding=utf-8


import requests
import json
from SendEmail import Email

class HttpConnect:

    def __init__(self):
        self.headers = {
            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
            'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'
        }

    def request_get(self, url):
        try:

            res = requests.get(url=url, headers=self.headers)

            if res.status_code == 200:
                return json.loads(res.text, encoding='utf-8')
            else:
                return ''
        except Exception as e:
            Email.sendErr()
            return ''

    def request_post(self, url, data):
        try:

            res = requests.post(url=url, headers=self.headers, json=data)

            if res.status_code == 200:
                return json.loads(res.text, encoding='utf-8')
            else:
                return ''
        except Exception as e:
            Email.sendErr()
            return ''


#
# http = HttpConnect()
# http.request_get("1231")