def ppFormatEquals(self, result, width, control, *args):
     stringstream = StringIO()
     pp = PrettyPrinter(stream=stringstream, width=width)
     format(pp, control, *args)
     self.assertEqual(result, stringstream.getvalue())
     pp.close()
     stringstream.close()
Esempio n. 2
0
 def decorator(*args, **kwargs):
     results = f(*args, **kwargs)
     if isinstance(results, dict):
         return {k: format(v) for k, v in results.items()}
     if isinstance(results, (list, tuple)):
         return type(results)(format(v) for v in results)
     return format(results)
 def ppFormatEquals(self, result, width, control, *args):
     stringstream = StringIO()
     pp = PrettyPrinter(stream=stringstream, width=width)
     format(pp, control, *args)
     self.assertEqual(result, stringstream.getvalue())
     pp.close()
     stringstream.close()
Esempio n. 4
0
 def test_format_1(self):
     # test simple formats
     self.assertEqual(format(12.454), 12.5)
     self.assertEqual(format(datetime(2015, 1, 27, 12, 0, 56, 345)), '2015-01-27 12:00:56')
     self.assertEqual(format('test'), 'test')
     self.assertEqual(format(123), 123)
     self.assertIsNone(format(None))
Esempio n. 5
0
def prepare_history(incsv, outcsv, daysperline):
    """given a input csv filename, which is a raw history csv file, each line
    contains only one day's info,
    and given daysperline, then this function generates a
    new csv file, each line contains multiple days info,
    finally this function returns a CSV object based on that new csv file.
    """

    format(incsv, outcsv, daysperline)
    return CSV(outcsv)
Esempio n. 6
0
 def test_get_info_2(self, board_calc):
     self.game.model.game_over(END_CHECKMATE, winner=WHITE)
     board_calc.return_value = 'board'
     expect = {
         'board': 'board',
         'started_at': format(self.game.model.date_created),
         'ended_at': format(self.game.model.date_end),
         'color': 'white',
         'opponent': 'anonymous',
         'winner': 'white',
     }
     self.assertEqual(self.game.get_info(), expect)
     board_calc.assert_called_once_with()
Esempio n. 7
0
 def post(self):
     fileName = self.request.body
     print(fileName)
     global test_sample_path
     global test_output_path
     fileName = fileName.decode()
     filenameIn = test_sample_path + '\\' + fileName
     filenameOut1 = test_output_path + '\\output.c'
     filenameOut2 = test_output_path + '\\outputInfo.txt'
     format.format(filenameIn, filenameOut1, filenameOut2)
     fileReadObj = open(filenameOut1)
     returnString = ''
     for fileString in fileReadObj.readlines():
         returnString = returnString + fileString
     self.write(returnString)
Esempio n. 8
0
 def post(self):
     fileName = self.request.body
     print(fileName)
     global test_sample_path
     global test_output_path
     fileName = fileName.decode()
     filenameIn = test_sample_path + '\\' + fileName
     filenameOut1 = test_output_path + '\\output.c'
     filenameOut2 = test_output_path + '\\outputInfo.txt'
     format.format(filenameIn, filenameOut1, filenameOut2)
     fileReadObj = open(filenameOut1)
     returnString = ''
     for fileString in fileReadObj.readlines():
         returnString = returnString + fileString
     self.write(returnString)
Esempio n. 9
0
    def convert(self, input, output=False):
        self.input = input
        self.length = len(input)

        #create lattice
        self.lattice = [[] for i in range(self.length + 2)]
        self.lattice[0].append(Node(' ', '<S>', '文頭', 1.0, 0, 1.0))
        self.lattice[-1].append(Node(' ', '</S>', '文末', 1.0, 0))
        for i in range(self.length):
            for j in range(i + 1, self.length + 1):
                yomi = input[i:j]
                for yomi, word, pos, prob in self.dictionary.get(yomi, []):
                    index = len(self.lattice[j])
                    node = Node(yomi, word, pos, prob, index)
                    self.lattice[j].append(node)

        #forward search
        for i in range(1, self.length + 2):
            for right in self.lattice[i]:
                j = i - len(right.yomi)
                if len(self.lattice[j]) == 0:
                    break

                def score(left):
                    if left.pos == '文頭': return 1.0
                    if right.pos == '文末': return left.total
                    return left.total * self.connection.get(
                        left.pos + "_" + right.pos, 0.0)

                best = None
                for node in self.lattice[j]:
                    if best == None or score(node) > score(best):
                        best = node
                right.total = right.prob * score(best)
                right.back = best.index
        if output:
            for node in self.lattice:
                print format(node)

        #back trace
        current = self.length
        position = self.lattice[self.length + 1][0].back
        self.result = []
        while current > 0:
            node = self.lattice[current][position]
            self.result.insert(0, node)
            position = node.back
            current -= len(node.yomi)
Esempio n. 10
0
 def test_format_2(self):
     # test dict, list and tuple with recursion
     cases = ((
         {'a': 1.11, 'b': {'c': 1.11, 'd': {'e': 1.11}}},
         [
             (1, {'a': 1.1, 'b': {'c': 1.11, 'd': {'e': 1.11}}}),
             (2, {'a': 1.1, 'b': {'c': 1.1, 'd': {'e': 1.11}}}),
         ]
     ), (
         [1.11, [1.11, [1.11]]],
         [
             (1, [1.1, [1.11, [1.11]]]),
             (2, [1.1, [1.1, [1.11]]]),
         ]
     ), (
         (1.11, (1.11, (1.11,))),
         [
             (1, (1.1, (1.11, (1.11,)))),
             (2, (1.1, (1.1, (1.11,)))),
         ]
     ), (
         (1.11, [{'a': 1.11, 'b': (1.11, [1.11])}, 1.22]),
         [
             (1, (1.1, [{'a': 1.11, 'b': (1.11, [1.11])}, 1.22])),
             (2, (1.1, [{'a': 1.11, 'b': (1.11, [1.11])}, 1.2])),
             (3, (1.1, [{'a': 1.1, 'b': (1.11, [1.11])}, 1.2])),
             (4, (1.1, [{'a': 1.1, 'b': (1.1, [1.11])}, 1.2])),
         ]
     ))
     for data, data_cases in cases:
         for level, expect in data_cases:
             self.assertEqual(format(data, level), expect)
Esempio n. 11
0
 def testPrintLevelLength(self):
     levelLengths = {
         (0, 1): "#",
         (1, 1): "(if ...)",
         (1, 2): "(if # ...)",
         (1, 3): "(if # # ...)",
         (1, 4): "(if # # #)",
         (2, 1): "(if ...)",
         (2, 2): "(if (member x ...) ...)",
         (2, 3): "(if (member x y) (+ # 3) ...)",
         (3, 2): "(if (member x ...) ...)",
         (3, 3): "(if (member x y) (+ (car x) 3) ...)",
         (3, 4): "(if (member x y) (+ (car x) 3) (foo (a b c d ...)))"
     }
     sexp = ("if", ("member", "x", "y"), ("+", ("car", "x"), 3),
             ("foo", ("a", "b", "c", "d", "Baz")))
     for (level, length) in [(0, 1), (1, 2), (1, 2), (1, 3), (1, 4), (2, 1),
                             (2, 2), (2, 3), (3, 2), (3, 3), (3, 4)]:
         with bindings(printervars,
                       print_pretty=True,
                       print_escape=False,
                       print_level=level,
                       print_length=length):
             s = format(None, "~W", sexp)
             self.assertEqual(levelLengths[(level, length)],
                              s.replace(",", ""))
Esempio n. 12
0
File: dog.py Progetto: jaketanwh/gp
def cls():
    global CLS_URL
    res = net.send(CLS_URL, 0)
    if res != -1:
        global CLS_CATCH_LIST
        baseinfo = format('__NEXT_DATA__ = ', '\n          module=', res)
        if len(baseinfo) <= 0:
            return
        global FIRST_INIT
        data = json.loads(baseinfo[0])
        dataList = data['props']['initialState']['telegraph']['dataList']
        for info in dataList:
            level = info['level']
            if level == 'B' or level == 'A':
                id = info['id']
                if id not in CLS_CATCH_LIST:
                    CLS_CATCH_LIST.append(id)
                    if FIRST_INIT != 1:
                        ctime = info['ctime']
                        # title = info['title']
                        content = info['content']
                        pat = re.compile(r'<[^>]+>', re.S)
                        content = pat.sub('', content)
                        # modified_time = info['modified_time']
                        ftime = time.strftime("%H:%M:%S", time.localtime(ctime))
                        qq.sendMsgToGroup('[财联社]' + '[' + ftime + ']' + content)

        if len(CLS_CATCH_LIST) > 30:
            CLS_CATCH_LIST.pop()
Esempio n. 13
0
def build():
    prebuild()
    format()
    print("🚧 Building")
    subprocess.call([
        "pyinstaller",
        "--onefile",
        "--icon=assets/favicon.ico",
        "--name",
        "hammer",
        "main.py",
    ])
    print("📌 copying config.yaml to output")
    shutil.copy("config.yaml", "dist")
    print("📌 copying skins.txt to output")
    shutil.copy("skins.txt", "dist")
    print("🎈 Build successfull")
Esempio n. 14
0
    def convert(self, input, output=False):
        self.input = input
        self.length = len(input)

        #create lattice
        self.lattice = [[] for i in range(self.length+2)]
        self.lattice[0].append(Node(' ', 'BOS', 0, 0, 0, 0))
        self.lattice[-1].append(Node(' ', 'EOS', 0, 0, 0, 0))
        for i in range(self.length):
            for j in range(i+1, self.length+1):
                yomi = input[i:j]
                for yomi, word, lid, rid, cost in self.dictionary.get(yomi, []):
                    index = len(self.lattice[j])
                    node = Node(yomi, word, lid, rid, cost, index)
                    self.lattice[j].append(node)

        #forward search
        for i in range(1, self.length+2):
            for right in self.lattice[i]:
                j = i - len(right.yomi)
                if len(self.lattice[j]) == 0:
                    break
                def score(left):
                    if left.rid == 0: return 0
                    if right.lid == 0: return left.total
                    return left.total + self.connection[left.rid][right.lid]
                best = None
                for node in self.lattice[j]:
                    if best == None or score(node) < score(best):
                        best = node
                right.total = right.cost + score(best)
                right.back = best.index
        if output:
            for node in self.lattice:
                print format(node)

        #back trace
        current = self.length
        position = self.lattice[self.length+1][0].back
        self.result = []
        while current > 0:
            node = self.lattice[current][position]
            self.result.insert(0, node)
            position = node.back
            current -= len(node.yomi)
Esempio n. 15
0
    def __init__(self, data, product, reference):
        self.data = data
        self.product = product
        self.reference = reference

        self.path = tempfile.mkdtemp()
        self.metrics = len(self.data)

        self.items = [ PerformanceReportItem(self.path, x) for x in format.format(self.data) ]
Esempio n. 16
0
    def convert(self, input, output=False):
        self.input = input
        self.length = len(input)

        #create lattice
        self.lattice = [[] for i in range(self.length+2)]
        self.lattice[0].append(Node(' ', '<S>', '文頭', 1.0, 0, 1.0))
        self.lattice[-1].append(Node(' ', '</S>', '文末', 1.0, 0))
        for i in range(self.length):
            for j in range(i+1, self.length+1):
                yomi = input[i:j]
                for yomi, word, pos, prob in self.dictionary.get(yomi, []):
                    index = len(self.lattice[j])
                    node = Node(yomi, word, pos, prob, index)
                    self.lattice[j].append(node)

        #forward search
        for i in range(1, self.length+2):
            for right in self.lattice[i]:
                j = i - len(right.yomi)
                if len(self.lattice[j]) == 0:
                    break
                def score(left):
                    if left.pos == '文頭': return 1.0
                    if right.pos == '文末': return left.total
                    return left.total * self.connection.get(left.pos+"_"+right.pos, 0.0)
                best = None
                for node in self.lattice[j]:
                    if best == None or score(node) > score(best):
                        best = node
                right.total = right.prob * score(best)
                right.back = best.index
        if output:
            for node in self.lattice: print format(node)

        #back trace
        current = self.length
        position = self.lattice[self.length+1][0].back
        self.result = []
        while current > 0:
            node = self.lattice[current][position]
            self.result.insert(0, node)
            position = node.back
            current -= len(node.yomi)
Esempio n. 17
0
def recv_message(conn):
    msg = []
    while(True):
        recved = conn.recv(buf) # contain the received message could be comlete or not
        msg.append(recved) # append the message to the list
        if recved[-2:] == "\r\a":
            put_together = "".join(msg) # put the message together
            put_together = put_together[0:-2] # remove the \r\a character
            print(format(put_together)) # print message in a nicely formatted way...
        send_message(conn)
        break
Esempio n. 18
0
 def msg(self, user, message, bold = False, underline = False, fg = False, bg = False):
     if isinstance(message, (list, tuple)):
         for m in message:
             self.msg(user, m, bold, underline, fg, bg)
         return
     else:
         message = str(message)
     message = format.format(message, bold, underline, fg, bg)
     for m in message.split('\n'):
         if m:
             irc.IRCClient.msg(self, user, m)
Esempio n. 19
0
def dump(data, options=None):
    config = {
        # 'verbose': True,
    }
    if options is not None:
        config.update(options)

    lines = []
    for key, val in data.iteritems():
        lines += format(key, val)

    # Adds Trailing newline
    lines.append('')

    return '\n'.join(lines)
Esempio n. 20
0
 def test_get_info_1(self, get_board, time_left):
     get_board.return_value = 'board'
     time_left.return_value = 12.567
     expect = {
         'board': 'board',
         'time_left': 12.6,
         'enemy_time_left': 12.6,
         'started_at': format(self.game.model.date_created),
         'ended_at': None,
         'next_turn': 'white',
         'color': 'white',
         'opponent': 'anonymous',
     }
     self.assertEqual(self.game.get_info(), expect)
     get_board.assert_called_once_with(WHITE)
     time_left.assert_has_calls([call(WHITE), call(BLACK)])
Esempio n. 21
0
File: app.py Progetto: jher5522/info
	def post(self):
                Input = self.request.arguments
		operator = Input['operator'][0]
		min = Input['min'][0]
		max = Input['max'][0]
		avg = Input['avg'][0]
		location = Input['location'][0]
		try:
			content = Input['content'] #contains a list of the displays that are required ['cnmae', 'sname']
		except:
			content = []

		#querie the sql database to get all the deatils of relevent birds
                #return birds as a list of birds. Each bird being a list a porperties
		birds = generalQuerie.querie(min, max, avg, location, operator)

		#create a list which contains only th info which will go in teh results table
		[birds, headrow, description] = format.format(birds, content, min, max, avg, location, operator)
		self.render("results.html", min=min, max=max,  birds=birds, headrow=headrow, description=description)
Esempio n. 22
0
	def execute(self,query,params=None):
		"""execute(query,{"param1" : value1,["param2" : value2,...]})

		DEFERRED

		Execute a query with he given parameters properly formatted.

		The parameter style is 'pyparam,' which uses a syntax like the 
		following:

		cursor.execute("SELECT * FROM PEOPLE WHERE name = %{name}s and age = %{age}s",{"name":"Joe",'age':29})
		"""
		d = Deferred()

		if not self.connection:
			reactor.callLater(0,d.errback,
			OperationalError("Cannot execute query: the connection has been closed"))
			return d

		self.description = None
		self.rowcount = -1


		self._callbackQ.append(d)

		s = format(query,params)

		if self._cid:
			self._query("CLOSE %s" % self._cid)
			self._cid = None

		if s[:7].upper() == "SELECT ":
			self._cid = self._genCid()
			s = "DECLARE %s CURSOR FOR (%s)" % (self._cid,s)
		else:
			self.connection._dirty = 1 # they have executed things other than SELECT

		self._query(s,self._done_execute)

		return d
Esempio n. 23
0
 def testPrintLevelLength(self):
     levelLengths = {
         (0, 1): "#",
         (1, 1): "(if ...)",
         (1, 2): "(if # ...)",
         (1, 3): "(if # # ...)",
         (1, 4): "(if # # #)",
         (2, 1): "(if ...)",
         (2, 2): "(if (member x ...) ...)",
         (2, 3): "(if (member x y) (+ # 3) ...)",
         (3, 2): "(if (member x ...) ...)",
         (3, 3): "(if (member x y) (+ (car x) 3) ...)",
         (3, 4): "(if (member x y) (+ (car x) 3) (foo (a b c d ...)))"
     }
     sexp = ("if", ("member", "x", "y"), ("+", ("car", "x"), 3),
             ("foo", ("a", "b", "c", "d", "Baz")))
     for (level, length) in [(0, 1), (1, 2), (1, 2), (1, 3), (1, 4),
                             (2, 1), (2, 2), (2, 3), (3, 2), (3, 3), (3, 4)]:
         with bindings(printervars,
                       print_pretty=True, print_escape=False,
                       print_level=level, print_length=length):
             s = format(None, "~W", sexp)
             self.assertEqual(levelLengths[(level, length)],
                              s.replace(",", ""))
Esempio n. 24
0
 def __str__(self):
     return format((self.yomi, self.word, self.lid, self.rid, self.cost, self.total, self.index, self.back))
Esempio n. 25
0
 def test_closeprice(self):
     format('data/testdata.csv', 'data/testdata-10dayperline.csv', 10)
     csv = CSV('data/testdata-10dayperline.csv')
     p = csv.closeprice(date='2015-07-15')
     self.failIf(p != 79.03)
Esempio n. 26
0
# program flow:
#   if 0    -> start server
#   if 6    -> keep requesting
#   if 7    -> confirm
#   else    -> HALT

while True:
    # Requesting data to internal internal API
    r_status = session.get(api_endpoint)

    # decoding JSON
    data = json.loads(r_status.text)

    # formatting and getting status
    status, title, content = format(data)
    print(status)

    if status == 0:
        print("let's enter the queue")

        # performing GET request to queue_URl in order to enter the queue
        r_queue = session.get(queue_url + '1')
        print(r_queue.text)

        # decoding JSON response text
        data = json.loads(r_queue.text)
        print(data)

        if not data["error"]:
            print('No errors')
Esempio n. 27
0
        entries = []
        for yomi, distance, values in results:
            for word, lid, rid, cost in values:
                total = cost + self.connection[lid]
                rank = total + (threshold - distance) * 5000
                entry = Entry(yomi, distance, word, lid, rid, cost, rank)
                entries.append(entry)
        entries.sort(key=lambda x: x.rank)
        return entries


if __name__ == '__main__':
    #parse options
    parser = OptionParser()
    parser.add_option("-d",
                      dest="dictionary",
                      default="data/mozc-dictionary.txt")
    parser.add_option("-c",
                      dest="connection",
                      default="data/mozc-connection.txt")
    parser.add_option("-t", dest="threshold", type="int", default=2)
    (options, args) = parser.parse_args()
    corrector = SpellingCorrector(options.dictionary, options.connection)

    #input from stdin
    for line in stdin:
        input = unicode(line.strip(), 'utf-8')
        result = corrector.correct(input, options.threshold)
        for i in result[:50]:
            print format(i)
Esempio n. 28
0
import format

filenameIn = '../test_sample/codeE7.c'              #input testSample
filenameOut1 = "../output/output.c"                 #output formatted codes
filenameOut2 = "../output/outputInfo.txt"           #output grammer analysis result
format.format(filenameIn, filenameOut1, filenameOut2)

filenameIn = '../output/output.c'                   #input testSample
filenameOut = "../output/outputSimplified.c"        #output simplified codes
format.simplify(filenameIn, filenameOut)

filenameIn = '../output/output.c'                   #input testSample
filenameOut = "../output/outputStyle1.c"            #output style codes
format.style(filenameIn, filenameOut)
Esempio n. 29
0
def prepare():
    format('data/03022007-07242015.csv', 'data/fv1_raw.csv', 14)
Esempio n. 30
0
    if options.filename != None:
        trie = Trie()
        for line in open(options.filename):
            key, value = line.strip().split(options.separator, 1)
            key, value = unicode(key, 'utf-8'), unicode(value, 'utf-8')
            trie.insert(key, value)

        for line in stdin:
            input = unicode(line.strip(), 'utf-8')
            # common prefix search
            if options.mode in ('all', 'common'):
                result = trie.common_prefix_search(input)
                print 'common prefix:'
                for i in result:
                    print format(i)
            # predictive search
            if options.mode in ('all', 'predict'):
                result = trie.predictive_search(input)
                print 'predict:'
                for i in result:
                    print format(i)
            # fuzzy search
            if options.mode in ('all', 'fuzzy'):
                result = trie.fuzzy_search_ex(input, options.distance)
                print 'fuzzy:'
                for i in result:
                    print format(i)

    else:
        trie = Trie()
Esempio n. 31
0
 def display(self, key="", depth=0):
     if self.values:
         print key + "\t" + format(self.values)
     for (k,v) in self.children.items():
         v.display(key + k, depth+1)
Esempio n. 32
0
 def __str__(self):
     return format((self.yomi, self.word, self.pos, self.prob, self.total,
                    self.index, self.back))
Esempio n. 33
0
 def __str__(self):
     return format((self.word, self.yomi, self.rank))
Esempio n. 34
0
import format

filenameIn = '../test_sample/codeE7.c'  #input testSample
filenameOut1 = "../output/output.c"  #output formatted codes
filenameOut2 = "../output/outputInfo.txt"  #output grammer analysis result
format.format(filenameIn, filenameOut1, filenameOut2)

filenameIn = '../output/output.c'  #input testSample
filenameOut = "../output/outputSimplified.c"  #output simplified codes
format.simplify(filenameIn, filenameOut)

filenameIn = '../output/output.c'  #input testSample
filenameOut = "../output/outputStyle1.c"  #output style codes
format.style(filenameIn, filenameOut)
Esempio n. 35
0
 def formatEquals(self, result, control, *args):
     self.assertEqual(result, format(None, control, *args))
Esempio n. 36
0
    def predict(self, input):
        results = self.trie.predictive_search(input)
        entries = []
        for yomi, values in results:
            for word, lid, rid, cost in values:
                total = cost + self.connection[lid]
                rank = total - int(1000 * log(1 + len(yomi) - len(input)))
                entry = Entry(yomi, word, lid, rid, cost, rank)
                entries.append(entry)
        entries.sort(key=lambda x:x.rank)
        return entries

if __name__ == '__main__':
    #parse options
    parser = OptionParser()
    parser.add_option("-d", dest="dictionary", default="data/mozc-dictionary.txt")
    parser.add_option("-c", dest="connection", default="data/mozc-connection.txt")
    parser.add_option("-t", dest="threshold", type="int", default=2)
    (options, args) = parser.parse_args()
    print "building trie.."
    predictor = Predictor(options.dictionary, options.connection)
    print "input in hiragana"

    #input from stdin
    for line in stdin:
        input = unicode(line.strip(), 'utf-8')
        result = predictor.predict(input)
        for i in result[:50]:
            print format(i)

Esempio n. 37
0
 def __str__(self):
     return format((self.word, self.yomi, self.rank))
Esempio n. 38
0
import csv
import math 
import format

# Using our new format function to create the two-list structure...
[data_amounts, data_recipients] = format.format('contributions.csv',0,7)

# Using standard python functions (and a little bit of creativity)
print "Maximum value: ",max(data_amounts)
print "Minimum value: ",min(data_amounts)
print "Mean value: ", sum(data_amounts)/len(data_amounts)
print "Median value: ", data_amounts[len(data_amounts)/2]
print "Range: ", abs(max(data_amounts) - min(data_amounts))



Esempio n. 39
0
 def test_format(self):
     format('data/testdata.csv', 'data/testdata-3dayperline.csv', 3)
     self.failIf(os.path.getsize('data/testdata-3dayperline.csv') <
                 os.path.getsize('data/testdata.csv') * 2)
Esempio n. 40
0
    if options.filename != None:
        trie = Trie()
        for line in open(options.filename):
            key, value = line.strip().split(options.separator, 1)
            key, value = unicode(key, 'utf-8'), unicode(value, 'utf-8')
            trie.insert(key, value)

        for line in stdin:
            input = unicode(line.strip(), 'utf-8')
            # common prefix search
            if options.mode in ('all', 'common'):
                result = trie.common_prefix_search(input)
                print 'common prefix:'
                for i in result:
                    print format(i)
            # predictive search
            if options.mode in ('all', 'predict'):
                result = trie.predictive_search(input)
                print 'predict:'
                for i in result:
                    print format(i)
            # fuzzy search
            if options.mode in ('all', 'fuzzy'):
                result = trie.fuzzy_search_ex(input, options.distance)
                print 'fuzzy:'
                for i in result:
                    print format(i)

    else:
        trie = Trie()
Esempio n. 41
0
    if beg != -1:
        beg += 22
        end = raw.index("</span>", beg)
    else:
        beg = raw.find('<div id="content">')
        if beg != -1:
            beg += 18
            end = raw.index("</div>", beg)
        else:
            beg = raw.index('zzz="') + 5
            beg = raw.index('"', beg) + 2
            end = raw.index("<!", beg)

    raw = raw[beg:end]
    raw = raw.replace("<BR>", "\n").replace("<br />", "\n")
    raw = format(raw.decode("gbk")).encode("gbk")
    sio = StringIO(raw)

    txt += title + "\n\n"

    for line in sio:
        txt += line.strip() + '\n'

    txt += '\n'

    print "Done crawling", title
    common.random_sleep(2)

with open(book_title + ".txt", "w") as outf:
    outf.write(txt)
Esempio n. 42
0
 def display(self, key="", depth=0):
     if self.values:
         print key + "\t" + format(self.values)
     for (k, v) in self.children.items():
         v.display(key + k, depth + 1)
Esempio n. 43
0
import csv
import math 
import format
import scipy.stats as scipy

### Doing more complicated statistics

###Manually -- see ttest.py

## Or use functions from libraries!

# Get data structure 
[data_amounts,data_recipient_party] = format.format('contributions.csv',0,5)

# Create array to feed into t-test function
x1,x2 = [],[]
for i in range(len(data_recipient_party)):
	if (data_recipient_party[i] == "R"):
		x1.append(data_amounts[i])
	if (data_recipient_party[i] == "D"):
		x2.append(data_amounts[i])

# Calculate
[t,p] = scipy.ttest_ind(x1,x2)

print "t: ",t," p: ",p
Esempio n. 44
0
 def __str__(self):
     return format((self.yomi, self.word, self.pos, self.prob, self.total,self.index,self.back))
Esempio n. 45
0
    if beg != -1:
        beg += 22
        end = raw.index("</span>", beg)
    else:
        beg = raw.find('<div id="content">')
        if beg != -1:
            beg += 18
            end = raw.index("</div>", beg)
        else:
            beg = raw.index('zzz="') + 5
            beg = raw.index('"', beg) + 2
            end = raw.index("<!", beg)

    raw = raw[beg:end]
    raw = raw.replace("<BR>", "\n").replace("<br />", "\n")
    raw = format(raw.decode("gbk")).encode("gbk")
    sio = StringIO(raw)

    txt += title + "\n\n"

    for line in sio:
        txt += line.strip() + '\n'

    txt += '\n'

    print "Done crawling", title
    common.random_sleep(2)

with open(book_title + ".txt", "w") as outf:
    outf.write(txt)
Esempio n. 46
0
							pass

	salesforce_file.close()
print('Got SFDC data')


reportinginput = 'false'



while reportinginput == 'false':
	ReportDict = ["Nielsen", "Eyeota Branded", "Eyeota Whitelabel", "LiveRamp", "TTD", "Lotame", "Appnexus"]
	UsageReportInput = input('Enter Usage report you are trying to format: ')

	for value in ReportDict:
		if UsageReportInput == value:
			reportinginput = 'true'
		else:
			pass
			
	if reportinginput == 'false':
		print('Please Enter a valid report: Nielsen or Eyeota Branded or Eyeota Whitelabel or LiveRamp or TTD or Lotame')

MonthInput = input('What is the month of the Usage Report? ')
YearInput = input('Year? ')

print('Starting formatting')
format.format(UsageReportInput,MonthInput,YearInput,SFDC,DSsegmentsData)

print('Finished!')