import os

from setuptools import setup, find_packages
from setuptools.command.install import install

import os, json
E = os.path.exists
J = os.path.join
MK = os.mkdir

ROOT_C = "/usr/local/etc/SocialOrigan"
INI = """
[path]
ROOT=/usr/local/etc/SocialOrigan

[proxy config]
type=socks5h
hostport=127.0.0.1:1080

[proxy 1]
type=socks5h
hostport=223.197.203.41:15356
"""

def initial():

	if not E(ROOT_C):
	    print("// init")
	    MK(ROOT_C)

	    with open(J(ROOT_C, "config.ini"), "w") as fp:
	        fp.write(INI)


	    codes = {
	        "ALL": "All:0",
	        "AD": "Andorra:1",
	        "AE": "United Arab Emirates:2",
	        "AF": "Afghanistan:3",
	        "AG": "Antigua and Barbuda:4",
	        "AI": "Anguilla:5",
	        "AL": "Albania:6",
	        "AM": "Armenia:7",
	        "AN": "Netherlands Antilles:8",
	        "AO": "Angola:9",
	        "AQ": "Antarctica:10",
	        "AR": "Argentina:11",
	        "AS": "American Samoa:12",
	        "AT": "Austria:13",
	        "AU": "Australia:14",
	        "AW": "Aruba:15",
	        "AX": "Aland Islands:16",
	        "AZ": "Azerbaijan:17",
	        "BA": "Bosnia and Herzegovina:18",
	        "BB": "Barbados:19",
	        "BD": "Bangladesh:20",
	        "BE": "Belgium:21",
	        "BF": "Burkina Faso:22",
	        "BG": "Bulgaria:23",
	        "BH": "Bahrain:24",
	        "BI": "Burundi:25",
	        "BJ": "Benin:26",
	        "BL": "Saint Barthelemy:27",
	        "BM": "Bermuda:28",
	        "BN": "Brunei Darussalam:29",
	        "BO": "Bolivia:30",
	        "BR": "Brazil:31",
	        "BS": "Bahamas:32",
	        "BT": "Bhutan:33",
	        "BV": "Bouvet Island:34",
	        "BW": "Botswana:35",
	        "BY": "Belarus:36",
	        "BZ": "Belize:37",
	        "CA": "Canada:38",
	        "CC": "Cocos (Keeling) Islands:39",
	        "CD": "Congo:40",
	        "CF": "Central African Republic:41",
	        "CG": "Congo:42",
	        "CH": "Switzerland:43",
	        "CI": "Cote d`Ivoire:44",
	        "CK": "Cook Islands:45",
	        "CL": "Chile:46",
	        "CM": "Cameroon:47",
	        "CN": "China:48",
	        "CO": "Colombia:49",
	        "CR": "Costa Rica:50",
	        "CU": "Cuba:51",
	        "CV": "Cape Verde:52",
	        "CX": "Christmas Island:53",
	        "CY": "Cyprus:54",
	        "CZ": "Czech Republic:55",
	        "DE": "Germany:56",
	        "DJ": "Djibouti:57",
	        "DK": "Denmark:58",
	        "DM": "Dominica:59",
	        "DO": "Dominican Republic:60",
	        "DZ": "Algeria:61",
	        "EC": "Ecuador:62",
	        "EE": "Estonia:63",
	        "EG": "Egypt:64",
	        "EH": "Western Sahara:65",
	        "ER": "Eritrea:66",
	        "ES": "Spain:67",
	        "ET": "Ethiopia:68",
	        "EU": "European Union:69",
	        "FI": "Finland:70",
	        "FJ": "Fiji:71",
	        "FK": "Falkland Islands:72",
	        "FM": "Micronesia:73",
	        "FO": "Faroe Islands:74",
	        "FR": "France:75",
	        "GA": "Gabon:76",
	        "GB": "United Kingdom:77",
	        "GD": "Grenada:78",
	        "GE": "Georgia:79",
	        "GF": "French Guiana:80",
	        "GG": "Guernsey:81",
	        "GH": "Ghana:82",
	        "GI": "Gibraltar:83",
	        "GL": "Greenland:84",
	        "GM": "Gambia:85",
	        "GN": "Guinea:86",
	        "GP": "Guadeloupe:87",
	        "GQ": "Equatorial Guinea:88",
	        "GR": "Greece:89",
	        "GS": "South Georgia and the South Sandwich Islands:90",
	        "GT": "Guatemala:91",
	        "GU": "Guam:92",
	        "GW": "Guinea-Bissau:93",
	        "GY": "Guyana:94",
	        "HK": "Hong Kong:95",
	        "HM": "Heard Island and McDonald Islands:96",
	        "HN": "Honduras:97",
	        "HR": "Croatia:98",
	        "HT": "Haiti:99",
	        "HU": "Hungary:100",
	        "ID": "Indonesia:101",
	        "IE": "Ireland:102",
	        "IL": "Israel:103",
	        "IM": "Isle of Man:104",
	        "IN": "India:105",
	        "IO": "British Indian Ocean Territory:106",
	        "IQ": "Iraq:107",
	        "IR": "Iran:108",
	        "IS": "Iceland:109",
	        "IT": "Italy:110",
	        "JE": "Jersey:111",
	        "JM": "Jamaica:112",
	        "JO": "Jordan:113",
	        "JP": "Japan:114",
	        "KE": "Kenya:115",
	        "KG": "Kyrgyzstan:116",
	        "KH": "Cambodia:117",
	        "KI": "Kiribati:118",
	        "KM": "Comoros:119",
	        "KN": "Saint Kitts and Nevis:120",
	        "KP": "North Korea:121",
	        "KR": "South Korea:122",
	        "KW": "Kuwait:123",
	        "KY": "Cayman Islands:124",
	        "KZ": "Kazakhstan:125",
	        "LA": "Lao People`s Democratic Republic:126",
	        "LB": "Lebanon:127",
	        "LC": "Saint Lucia:128",
	        "LI": "Liechtenstein:129",
	        "LK": "Sri Lanka:130",
	        "LR": "Liberia:131",
	        "LS": "Lesotho:132",
	        "LT": "Lithuania:133",
	        "LU": "Luxembourg:134",
	        "LV": "Latvia:135",
	        "LY": "Libyan Arab Jamahiriya:136",
	        "MA": "Morocco:137",
	        "MC": "Monaco:138",
	        "MD": "Moldova:139",
	        "ME": "Montenegro:140",
	        "MF": "Saint Martin:141",
	        "MG": "Madagascar:142",
	        "MH": "Marshall Islands:143",
	        "MK": "Macedonia:144",
	        "ML": "Mali:145",
	        "MM": "Myanmar:146",
	        "MN": "Mongolia:147",
	        "MO": "Macao:148",
	        "MP": "Northern Mariana Islands:149",
	        "MQ": "Martinique:150",
	        "MR": "Mauritania:151",
	        "MS": "Montserrat:152",
	        "MT": "Malta:153",
	        "MU": "Mauritius:154",
	        "MV": "Maldives:155",
	        "MW": "Malawi:156",
	        "MX": "Mexico:157",
	        "MY": "Malaysia:158",
	        "MZ": "Mozambique:159",
	        "NA": "Namibia:160",
	        "NC": "New Caledonia:161",
	        "NE": "Niger:162",
	        "NF": "Norfolk Island:163",
	        "NG": "Nigeria:164",
	        "NI": "Nicaragua:165",
	        "NL": "Netherlands:166",
	        "NO": "Norway:167",
	        "NP": "Nepal:168",
	        "NR": "Nauru:169",
	        "NU": "Niue:170",
	        "NZ": "New Zealand:171",
	        "OM": "Oman:172",
	        "PA": "Panama:173",
	        "PE": "Peru:174",
	        "PF": "French Polynesia:175",
	        "PG": "Papua New Guinea:176",
	        "PH": "Philippines:177",
	        "PK": "Pakistan:178",
	        "PL": "Poland:179",
	        "PM": "Saint Pierre and Miquelon:180",
	        "PN": "Pitcairn:181",
	        "PR": "Puerto Rico:182",
	        "PS": "Palestinian Territory:183",
	        "PT": "Portugal:184",
	        "PW": "Palau:185",
	        "PY": "Paraguay:186",
	        "QA": "Qatar:187",
	        "RE": "Reunion:188",
	        "RO": "Romania:189",
	        "RS": "Serbia:190",
	        "RU": "Russian Federation:191",
	        "RW": "Rwanda:192",
	        "SA": "Saudi Arabia:193",
	        "SB": "Solomon Islands:194",
	        "SC": "Seychelles:195",
	        "SD": "Sudan:196",
	        "SE": "Sweden:197",
	        "SG": "Singapore:198",
	        "SH": "Saint Helena:199",
	        "SI": "Slovenia:200",
	        "SJ": "Svalbard and Jan Mayen:201",
	        "SK": "Slovakia:202",
	        "SL": "Sierra Leone:203",
	        "SM": "San Marino:204",
	        "SN": "Senegal:205",
	        "SO": "Somalia:206",
	        "SR": "Suriname:207",
	        "ST": "Sao Tome and Principe:208",
	        "SU": "Soviet Union (being phased out):209",
	        "SV": "El Salvador:210",
	        "SY": "Syrian Arab Republic:211",
	        "SZ": "Swaziland:212",
	        "TC": "Turks and Caicos Islands:213",
	        "TD": "Chad:214",
	        "TF": "French Southern Territories:215",
	        "TG": "Togo:216",
	        "TH": "Thailand:217",
	        "TJ": "Tajikistan:218",
	        "TK": "Tokelau:219",
	        "TL": "Timor-Leste:220",
	        "TM": "Turkmenistan:221",
	        "TN": "Tunisia:222",
	        "TO": "Tonga:223",
	        "TP": "Portuguese Timor (being phased out):224",
	        "TR": "Turkey:225",
	        "TT": "Trinidad and Tobago:226",
	        "TV": "Tuvalu:227",
	        "TW": "Taiwan:228",
	        "TZ": "Tanzania:229",
	        "UA": "Ukraine:230",
	        "UG": "Uganda:231",
	        "UK": "United Kingdom:232",
	        "UM": "United States Minor Outlying Islands:233",
	        "US": "United States:234",
	        "UY": "Uruguay:235",
	        "UZ": "Uzbekistan:236",
	        "VA": "Holy See (Vatican City State):237",
	        "VC": "Saint Vincent and the Grenadines:238",
	        "VE": "Venezuela:239",
	        "VG": "Virgin Islands, British:240",
	        "VI": "Virgin Islands, U.S.:241",
	        "VN": "VietNam:242",
	        "VU": "Vanuatu:243",
	        "WF": "Wallis and Futuna:244",
	        "WS": "Samoa:245",
	        "YE": "Yemen:246",
	        "YT": "Mayotte:247",
	        "YU": "Yugoslavia:248",
	        "ZA": "South Africa:249",
	        "ZM": "Zambia:250",
	        "ZW": "Zimbabwe:251",
	        "A1": "Anonymous Proxies:252",
	        "A2": "Satellite Providers:253",
	        "AP": "Asia/Pacific Region:254",
	        "O1": "Other Country:255",
	        "CW": "Curacao:256",
	        "CS": "Czechoslovakia:257",
	        "SX": "Sint Maarten:258",
	        "SS": "South Sudan:259"
	    }

	    json.dump(codes, open(J(ROOT_C, 'country_code.json'), 'w'))


class MyInstall(install):

    def run(self):
        initial()
        print(" ... ...............")
        install.run(self)
        

# in the setup function:
# cmdclass={}

setup(name='SocialOrgan',
    version='0.1',
    cmdclass={
        'install': MyInstall,
    },
    description='a simple way to ...',
    url='https://github.com/xxx/xx.git',
    author='xxx',
    author_email='darkhackdevil@gmail.com',
    license='MIT',
    zip_safe=False,
    packages=find_packages(),
    install_requires=['aiohttp==2.3.10',
    	'aiosocks==0.2.6',
    	'bs4',
    	'lxml',
    	'requests',
    	'pysocks5',
    	'termcolor',
    	'PySocks==1.6.7',
    	'pyexecjs==1.5.1',
    	'mroylib-min==1.4.1',
    ],
    entry_points={
        'console_scripts': ['freeproxy=SocialOrigan.cmd:run']
    },



)


