예제 #1
0
def sort_by_date(vers):
    lst = [[date, ver] for ver, date in vers.items()]
    lst.sort()
    sorted = odic()
    for date, ver in lst:
        sorted[ver] = date
    return sorted
예제 #2
0
def get_package_info(p, stable_only=True, debug=False):
    dates = get_package_dates(p)
    if not dates:
        return None
    cmd = ["pip", "install", "{0}==blarchy".format(p)]
    s, ok = rrun(cmd)
    if ok:
        raw = s.split(",")
        raw[0] = raw[0].split("versions:")[1].strip()
        raw[-1] = raw[-1].split(")\n")[0].strip()
        # pprint(raw)
        vers = odic()
        for x in raw:
            x = x.strip()
            if stable_only:
                if not ver_is_stable(x):
                    continue
            if x in dates:
                vers[x] = dates[x]
            else:
                if debug:
                    print("# Warning: version in pip not in pypi:", x)
        for x in dates:
            if not ver_is_stable(x):
                continue
            if x not in vers:
                if debug:
                    print("# Warning: version in pypi not in pip:", x)
        if len(vers) == 0 and stable_only:
            print("# Warning: No candidates found for {0} - try --unstable".
                  format(p))
        return vers
예제 #3
0
def get_package_dates(p):
    #https://pypi.org/pypi/mido/json
    url = "https://pypi.org/pypi/{0}/json".format(p)
    j = requests.get(url).content
    try:
        data = json.loads(j)
    except:
        print("# warning: could not find page for {0}".format(p))
        return None
    vers = odic()
    for x in data['releases']:
        for y in data['releases'][x]:
            # print (x, y['upload_time'])
            date = dup.parse(y['upload_time'])
            vers[x] = date  # FIXME: multiple uploads possible
    return vers
예제 #4
0
    def __init__(self, status=None, message=None):
        """
        Nagios responses are expected to be in a very specific format, and
        this class allows these responses to easily be built up and extracted
        in the proper format.

        This class makes it easy to set the status, message, and performance
        data for a response.

        :Parameters:
          - `status` (optional): A :py:class:`~pynagios.status.Status` object
            representing the status of the response.
          - `message` (optional): An information message to include with the
            output.
        """
        self.status = status
        self.message = message
        self.perf_data = odic({})
예제 #5
0
#coding=utf-8
'''
比较只留中文和什么都不去除的区别
'''
from __future__ import  division
import sys
reload(sys)
sys.setdefaultencoding('utf-8')  # @UndefinedVariable
import toolkit.data as dt
from collections import OrderedDict as odic

dic_write=odic({})
with open(r'./data_in/traffic_word.txt','rb') as somefile:
    for line in somefile:
        word= line.strip() #去除换行符号
        word=dt.getunicode(word)
        dic_write[word]=[[],[]] # 第一个为Chinese 第二个装非chinese

import gensim

# 第一个模型
model = gensim.models.Word2Vec.load_word2vec_format("chinese_out.vector", binary=False)

for word in dic_write:
    try:   
        b=model.most_similar(word,topn=30)
        for tu in b:
            dic_write[word][0].append(tu[0]+str(tu[1])) 
    except:   
        dic_write[word][0]=["该词不存在于词典"]
    finally:
예제 #6
0
###练习8 简单统计
from collections import Counter
import pandas as ps
from collections import OrderedDict as odic

content = ps.read_csv("./data.csv")
print(content, "\n", type(content))

print(content.values[0])

c = Counter(content.values[0])

data = {"go": "0.1", "java": "1.9", "python": "1.6", "c++": "3.0"}

order = odic(data)

print(order)