<commit_before>#!/usr/bin/env python
"""

 ____       _____             _                _           _     
|  _ \ _   |_   _|__ _ __    / \   _ __   __ _| |_   _ ___(_)___ 
| |_) | | | || |/ __| '_ \  / _ \ | '_ \ / _` | | | | / __| / __|
|  __/| |_| || | (__| | | |/ ___ \| | | | (_| | | |_| \__ \ \__ \
|_|    \__, ||_|\___|_| |_/_/   \_\_| |_|\__,_|_|\__, |___/_|___/
       |___/                                     |___/           

t.cn JSON and XML Analysis - v0.2Fix
By iPixelOldC & http://hoc117.top
License: MIT
"""

import json
import xml.etree.cElementTree as et
import urllib.request
import re
import os

def JSONReturn(site):
    """
    json analysis: JSONReturn(site='Website URL(format:http[s]://xxx)')
    return: {'url_short': 'http://t.cn/xxx', 'url_long': site, 'type': 0}
    type: 链接的类型，0：普通网页(site page)、1：视频(video)、2：音乐(music)、3：活动(activity)、5、投票(vote)
    """
    response = urllib.request.urlopen('http://api.t.sina.com.cn/short_url/shorten.json?source=3271760578&url_long={0!s}'.format((site)))
    html = response.read().decode('utf8')
    loads = json.loads(str(html))
    return loads[0]

def XMLReturn(site):
    """
    xml analysis: XMLReturn(site='Website URL(format:http[s]://xxx)')
    return: {'url_short': 'http://t.cn/xxx', 'url_long': site}
    """
    response = urllib.request.urlopen('http://api.t.sina.com.cn/short_url/shorten.xml?source=3271760578&url_long={0!s}'.format((site)))
    html = response.read().decode('utf8')
    loads = et.fromstring(str(html))[0]
    return {"url_short": loads[0].text, "url_long": loads[1].text, "type": loads[2].text}

if __name__ == "__main__":
    print(__doc__)
    inputurl = input('>>Please enter url: ')
    if 'http://' in inputurl:
        pass
    else:
        inputurl = 'http://'+inputurl
    while True:
        inputJorX = input('>>(x)ml or (j)son: ').lower()
        if inputJorX not in ('x', 'j'):
            print("> Please enter 'x' or 'j'!")
        else:
            break
    if 'x' == inputJorX:
        r_xml = XMLReturn(inputurl)
        print(">>{0!s}: \n> Short URL: {1!s}".format(r_xml["url_long"], r_xml["url_short"]))
    if 'j' == inputJorX:
        r_json = JSONReturn(inputurl)
        print(">>{0!s}: \n> Short URL: {1!s}".format(r_json["url_long"], r_json["url_short"]))
    while True:
        save_yn = input('>>Do you want to save it?[Y/n]').lower()
        if save_yn == 'n':
            break
        elif save_yn == 'y':
            print("> Saving...")
            open('{0!s}.json'.format((re.search(r'(http://+)(.*)', inputurl).group(2))), 'w+').write(str(JSONReturn(inputurl)))
            print("> OK")
            break
        else:
            print('Please enter (y) or ()')<commit_msg>fix 2<commit_after>#!/usr/bin/env python
"""

 ____       _____             _                _           _     
|  _ \ _   |_   _|__ _ __    / \   _ __   __ _| |_   _ ___(_)___ 
| |_) | | | || |/ __| '_ \  / _ \ | '_ \ / _` | | | | / __| / __|
|  __/| |_| || | (__| | | |/ ___ \| | | | (_| | | |_| \__ \ \__ \
|_|    \__, ||_|\___|_| |_/_/   \_\_| |_|\__,_|_|\__, |___/_|___/
       |___/                                     |___/           

t.cn JSON and XML Analysis - v0.2Fix
By iPixelOldC & http://hoc117.top
License: MIT
"""

import json
import xml.etree.cElementTree as et
import urllib.request
import re
import os

def JSONReturn(site):
    """
    json analysis: JSONReturn(site='Website URL(format:http[s]://xxx)')
    return: {'url_short': 'http://t.cn/xxx', 'url_long': site, 'type': 0}
    type: 链接的类型，0：普通网页(site page)、1：视频(video)、2：音乐(music)、3：活动(activity)、5、投票(vote)
    """
    response = urllib.request.urlopen('http://api.t.sina.com.cn/short_url/shorten.json?source=3271760578&url_long={0!s}'.format((site)))
    html = response.read().decode('utf8')
    loads = json.loads(str(html))
    return loads[0]

def XMLReturn(site):
    """
    xml analysis: XMLReturn(site='Website URL(format:http[s]://xxx)')
    return: {'url_short': 'http://t.cn/xxx', 'url_long': site}
    """
    response = urllib.request.urlopen('http://api.t.sina.com.cn/short_url/shorten.xml?source=3271760578&url_long={0!s}'.format((site)))
    html = response.read().decode('utf8')
    loads = et.fromstring(str(html))[0]
    return {"url_short": loads[0].text, "url_long": loads[1].text, "type": loads[2].text}

if __name__ == "__main__":
    print(__doc__)
    inputurl = input('>>Please enter url: ')
    if 'http://' in inputurl:
        pass
    else:
        inputurl = 'http://'+inputurl
    while True:
        inputJorX = input('>>(x)ml or (j)son: ').lower()
        if inputJorX not in ('x', 'j'):
            print("> Please enter 'x' or 'j'!")
        else:
            break
    if 'x' == inputJorX:
        r_xml = XMLReturn(inputurl)
        print(">>{0!s}: \n> Short URL: {1!s}".format(r_xml["url_long"], r_xml["url_short"]))
    if 'j' == inputJorX:
        r_json = JSONReturn(inputurl)
        print(">>{0!s}: \n> Short URL: {1!s}".format(r_json["url_long"], r_json["url_short"]))
    while True:
        save_yn = input('>>Do you want to save it?[Y/n]').lower()
        if save_yn == 'n':
            break
        elif save_yn == 'y':
            print("> Saving...")
            open('{0!s}.json'.format((re.search(r'(http://+)(.*)', inputurl).group(2))), 'w+').write(str(JSONReturn(inputurl)))
            print("> OK")
            break
        else:
            print('Please enter (y) or (n)')
{'fraction_non_alphanumeric': 0.21006080707573244, 'fraction_numerical': 0.017136539524599224, 'mean_word_length': 2.363073110285006, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4773891', 'n_tokens_mistral': 2099, 'n_tokens_neox': 2073, 'n_words': 324}