当前位置: 首页>>代码示例>>Python>>正文


Python Helper.makeDateObject方法代码示例

本文整理汇总了Python中Helper.Helper.makeDateObject方法的典型用法代码示例。如果您正苦于以下问题:Python Helper.makeDateObject方法的具体用法?Python Helper.makeDateObject怎么用?Python Helper.makeDateObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Helper.Helper的用法示例。


在下文中一共展示了Helper.makeDateObject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: readFile

# 需要导入模块: from Helper import Helper [as 别名]
# 或者: from Helper.Helper import makeDateObject [as 别名]
    def readFile(self, url):
        try:
            f = open(url, 'r')
        except:
            print('File not found')
            newPath = input('Enter new path > ');
            return self.readFile(newPath) #TODO: this doesn't work for entirely unknown reasons

        newdate = re.compile('\s*([0-9]{1,2}-[0-9]{1,2}-[0-9]{2})\s*')
        currentDateStr = None
        currentDateObj = None
        numWords = 0
        namesFound = set()
        totalWordNum = 0

        currentDayEntry = '' #holds all the lines for the current day, so we can compute a hash of the day later on
        
        line = f.readline()
        while (line != ''):
            if self.prefs.GUESS_NAMES:
                self.guessNames(line)
            #check a line to see if it's a date, therefore a new day
            dateFound = newdate.match(line)
            if dateFound != None: #it's a new date, so wrapup the previous date and set up to move onto the next one
                if namesFound != None:
                    self.addRelatedNames(namesFound)
                    namesFound = set()
                    self.dayEntryHashTable[currentDateObj] = hashlib.md5(currentDayEntry.encode()) #TODO: deal with first date

                if numWords > 0:
                    self.wordCountOfEntriesDict[currentDateObj] = numWords #should be here, since we want it triggered at the end
                totalWordNum += numWords
                numWords = 0
                currentDateStr = dateFound.group(0)
                currentDateStr = Helper.formatDateStringIntoCleanedString(currentDateStr)
                currentDateObj = Helper.makeDateObject(currentDateStr)

                if currentDateObj > self.mostRecentDate: #found a higher date than what we've seen so far
                    self.mostRecentDate = currentDateObj
                if currentDateObj < self.firstDate: #found a lower date than what we have now
                    self.firstDate = currentDateObj
                line = line[len(currentDateStr):] #remove date from line, so it's not a word

            if currentDateStr != None:
                (wordsFound, namesFoundThisLine) = self.addLine(line, currentDateObj)
                for name in namesFoundThisLine:
                    namesFound.add(name)
                numWords += wordsFound
            line = f.readline()
            currentDayEntry += line #add line to the day's entry

        #need to capture the last date for the entry length
        self.wordCountOfEntriesDict[currentDateObj] = numWords 
        self.totalNumberOfWords = totalWordNum + numWords #need to get words from last line
        f.close()
开发者ID:dirkstahlecker,项目名称:WordFrequencies,代码行数:57,代码来源:WordFrequenciesClass.py

示例2: TestUM

# 需要导入模块: from Helper import Helper [as 别名]
# 或者: from Helper.Helper import makeDateObject [as 别名]
from WordDict import WordDict
from Helper import Helper
import unittest
from WordFrequenciesClass import WordFrequencies
from datetime import datetime
import argparse
from io import StringIO
import sys

date = Helper.makeDateObject('10-12-17')

class TestUM(unittest.TestCase):
    wd = WordDict()

    @classmethod
    def setUpClass(self):
        self.wd.addWord('word1', 1, date, date, False)
        self.wd.addWord('word2', 1, date, date, False)
        self.wd.addWord('word3', 1, date, date, False)

    @classmethod
    def tearDownClass(self):
        pass

    def test_addWordNoConflicts(self):
        self.assertEqual(self.wd.getCount('word1'), 1)
        self.assertEqual(self.wd.getFirstOccurrence('word1'), date)

    def test_incrementCount(self):
        self.wd.incrementCount('word1')
        self.assertEqual(self.wd.getCount('word1'), 2)
开发者ID:dirkstahlecker,项目名称:WordFrequencies,代码行数:33,代码来源:WordDictTest.py


注:本文中的Helper.Helper.makeDateObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。