예제 #1
0
파일: views.py 프로젝트: yrjie/Rghoul
def updateSp(request):
    today = utils.getToday()
    todayD = dateutil.parser.parse(today).date()
    allDishes = json.loads(request.body)
    cnt = 0
    for x in allDishes:
        rs = Dish.objects.filter(pid=x["id"], date__range=(todayD, todayD))
        if rs:
            continue
        d0 = Dish()
        if rs:
            d0.date = rs[0].date
        d0.pid = x["id"]
        d0.name = x["name"]
        d0.booth = x["booth"]
        d0.ingredient = x["ingredient"]
        if "<Simple Wamen>" in x["name"]:
            d0.energy = 320
        else:
            d0.energy = x["energy"]
        d0.price = x["price"]
        d0.mealTime = x["mealTime"]
        d0.floor = x["floor"]
        d0.like = 0
        d0.dislike = 0
        d0.save()
        cnt += 1
    return HttpResponse("INFO(SP): updated %d pictures" % cnt)
예제 #2
0
파일: views.py 프로젝트: yrjie/Rghoul
def updateSp(request):
    today = utils.getToday()
    todayD = dateutil.parser.parse(today).date()
    allDishes = json.loads(request.body)
    cnt = 0
    for x in allDishes:
        rs = Dish.objects.filter(pid=x["id"], date__range=(todayD, todayD))
        if rs:
            continue
        d0 = Dish()
        if rs:
            d0.date = rs[0].date
        d0.pid = x["id"]
        d0.name = x["name"]
        d0.booth = x["booth"]
        d0.ingredient = x["ingredient"]
        if "<Simple Wamen>" in x["name"]:
            d0.energy = 320
        else:
            d0.energy = x["energy"]
        d0.price = x["price"]
        d0.mealTime = x["mealTime"]
        d0.floor = x["floor"]
        d0.like = 0
        d0.dislike = 0
        d0.save()
        cnt += 1
    return HttpResponse("INFO(SP): updated %d pictures" % cnt)
예제 #3
0
파일: views.py 프로젝트: yrjie/Rghoul
def update(request):
    today = utils.getToday()
    prefix = settings.BASE_DIR + "/static/data/" + today
    if not os.path.exists(prefix):
        return HttpResponse("ERROR: today's pictures are not uploaded.")
    lunch9, lunch22, dinner9, dinner22 = utils.getFileLists()
    
    todayD = dateutil.parser.parse(today).date()
    pics = Picture.objects.filter(date__range=(todayD, todayD))
    cnt = 0
    for file in lunch9:
        if len(pics.filter(picName=file)) == 0:
            pic = Picture(picName=file, mealTime="L", floor=9, like=0, dislike=0)
            pic.save()
            cnt += 1
    for file in lunch22:
        if len(pics.filter(picName=file)) == 0:
            pic = Picture(picName=file, mealTime="L", floor=22, like=0, dislike=0)
            pic.save()
            cnt += 1
    for file in dinner9:
        if len(pics.filter(picName=file)) == 0:
            pic = Picture(picName=file, mealTime="D", floor=9, like=0, dislike=0)
            pic.save()
            cnt += 1
    for file in dinner22:
        if len(pics.filter(picName=file)) == 0:
            pic = Picture(picName=file, mealTime="D", floor=22, like=0, dislike=0)
            pic.save()
            cnt += 1
    return HttpResponse("INFO: updated %d pictures" % cnt)
예제 #4
0
파일: views.py 프로젝트: yrjie/Rghoul
def getOpenPolls():
    polls = {}
    today = utils.getToday()
    rs = Poll.objects.filter(open=True, parent=today)
    for p in rs:
        info = []
        info.append(p.title)
        info.append(p.owner)
        info.append(p.count)
        polls[p.code] = info
    return polls
예제 #5
0
파일: views.py 프로젝트: yrjie/Rghoul
def getOpenPolls():
    polls = {}
    today = utils.getToday()
    rs = Poll.objects.filter(open=True, parent=today)
    for p in rs:
        info = []
        info.append(p.title)
        info.append(p.owner)
        info.append(p.count)
        polls[p.code] = info
    return polls
예제 #6
0
파일: views.py 프로젝트: yrjie/Rghoul
def createPoll(request):
    if not request.POST:
        folders = utils.getDateList()
        if utils.getNowH() >= utils.dinnerH:
            meal = "dinner"
        else:
            meal = "lunch"
        return render_to_response("createpoll.html", {
            "folders": folders,
            "meal": meal
        })
    codeLen = 8
    codeChars = string.ascii_uppercase + string.ascii_lowercase + string.digits
    code = ""
    while True:
        code = "".join(random.choice(codeChars) for _ in range(codeLen))
        if not Poll.objects.filter(code=code):
            break
    owner = utils.escapeHtml(request.POST["owner"])
    if not owner:
        owner = utils.getMaskedIp(request)
    title = utils.escapeHtml(request.POST["title"])
    if not title:
        title = "%s's poll" % owner
    open = "open" in request.POST
    p = Poll(owner=owner,
             title=title,
             open=open,
             parent=utils.getToday(),
             code=code,
             count=0)
    result = {}
    result["0_-1"] = []  # any
    result["9_-1"] = []  # 9 any
    result["22_-1"] = []  # 22 any
    lunch9, lunch22, dinner9, dinner22 = utils.getFileLists()
    if utils.getNowH() >= utils.dinnerH:
        dish9 = [int(x.split(".")[0]) for x in dinner9]
        dish22 = [int(x.split(".")[0]) for x in dinner22]
    else:
        dish9 = [int(x.split(".")[0]) for x in lunch9]
        dish22 = [int(x.split(".")[0]) for x in lunch22]
    for d in dish9:
        result["9_" + str(d)] = []
    for d in dish22:
        result["22_" + str(d)] = []
    p.result = json.dumps(result)
    p.save()
    return redirect("/poll/%s/" % code)
예제 #7
0
파일: views.py 프로젝트: yrjie/Rghoul
def update(request):
    today = utils.getToday()
    prefix = settings.BASE_DIR + "/static/data/" + today
    if not os.path.exists(prefix):
        return HttpResponse("ERROR: today's pictures are not uploaded.")
    lunch9, lunch22, dinner9, dinner22 = utils.getFileLists()

    todayD = dateutil.parser.parse(today).date()
    pics = Picture.objects.filter(date__range=(todayD, todayD))
    cnt = 0
    for file in lunch9:
        if len(pics.filter(picName=file)) == 0:
            pic = Picture(picName=file,
                          mealTime="L",
                          floor=9,
                          like=0,
                          dislike=0)
            pic.save()
            cnt += 1
    for file in lunch22:
        if len(pics.filter(picName=file)) == 0:
            pic = Picture(picName=file,
                          mealTime="L",
                          floor=22,
                          like=0,
                          dislike=0)
            pic.save()
            cnt += 1
    for file in dinner9:
        if len(pics.filter(picName=file)) == 0:
            pic = Picture(picName=file,
                          mealTime="D",
                          floor=9,
                          like=0,
                          dislike=0)
            pic.save()
            cnt += 1
    for file in dinner22:
        if len(pics.filter(picName=file)) == 0:
            pic = Picture(picName=file,
                          mealTime="D",
                          floor=22,
                          like=0,
                          dislike=0)
            pic.save()
            cnt += 1
    return HttpResponse("INFO: updated %d pictures" % cnt)
예제 #8
0
파일: views.py 프로젝트: yrjie/Rghoul
def createPoll(request):
    if not request.POST:
        folders = utils.getDateList()
        if utils.getNowH() >= utils.dinnerH:
            meal = "dinner"
        else:
            meal = "lunch"
        return render_to_response("createpoll.html", {"folders":folders, "meal":meal})
    codeLen = 8
    codeChars = string.ascii_uppercase+string.ascii_lowercase+string.digits
    code = ""
    while True:
        code = "".join(random.choice(codeChars) for _ in range(codeLen))
        if not Poll.objects.filter(code=code):
            break
    owner = utils.escapeHtml(request.POST["owner"])
    if not owner:
        owner = utils.getMaskedIp(request)
    title = utils.escapeHtml(request.POST["title"])
    if not title:
        title = "%s's poll" % owner
    open = "open" in request.POST
    p = Poll(owner=owner, title=title, open=open, parent=utils.getToday(), code=code, count=0)
    result = {}
    result["0_-1"] = []  # any
    result["9_-1"] = []  # 9 any
    result["22_-1"] = []  # 22 any
    lunch9, lunch22, dinner9, dinner22 = utils.getFileLists()
    if utils.getNowH() >= utils.dinnerH:
        dish9 = [int(x.split(".")[0]) for x in dinner9]
        dish22 = [int(x.split(".")[0]) for x in dinner22]
    else:
        dish9 = [int(x.split(".")[0]) for x in lunch9]
        dish22 = [int(x.split(".")[0]) for x in lunch22]
    for d in dish9:
        result["9_"+str(d)] = []
    for d in dish22:
        result["22_"+str(d)] = []
    p.result = json.dumps(result)
    p.save()
    return redirect("/poll/%s/" % code)
예제 #9
0
파일: views.py 프로젝트: yrjie/Rghoul
def comment(request, date=None):
    res = ""
    if request.POST.has_key("context") and len(request.POST["context"])>0:
        maxLen = Comment._meta.get_field("context").max_length
        author = utils.escapeHtml(request.POST["author"])
        if len(author) == 0:
            author = utils.getMaskedIp(request)
        if author == "admin@mars":
            res = "<dt><font color=\"orange\">%s</font></dt>" % "admin"
        else:
            res = "<dt>%s</dt>" % author
        context = utils.escapeHtml(request.POST["context"].replace("\r\n", "\n"))
        for line in context.split("\n"):
            res += "\r\n<dd>%s</dd>" % line
        res = res[0:maxLen-55]
        context = res
        parent = utils.getToday()
        cmt = Comment(author=author, context=context, parent=parent)
        cmt.save()
        res += utils.getPdate(cmt.date)
    return HttpResponse(res)
예제 #10
0
파일: views.py 프로젝트: yrjie/Rghoul
def comment(request, date=None):
    res = ""
    if request.POST.has_key("context") and len(request.POST["context"]) > 0:
        maxLen = Comment._meta.get_field("context").max_length
        author = utils.escapeHtml(request.POST["author"])
        if len(author) == 0:
            author = utils.getMaskedIp(request)
        if author == "admin@mars":
            res = "<dt><font color=\"orange\">%s</font></dt>" % "admin"
        else:
            res = "<dt>%s</dt>" % author
        context = utils.escapeHtml(request.POST["context"].replace(
            "\r\n", "\n"))
        for line in context.split("\n"):
            res += "\r\n<dd>%s</dd>" % line
        res = res[0:maxLen - 55]
        context = res
        parent = utils.getToday()
        cmt = Comment(author=author, context=context, parent=parent)
        cmt.save()
        res += utils.getPdate(cmt.date)
    return HttpResponse(res)
예제 #11
0
        return {'ticker': ticker, 'message': message, 'dataFrame': actual}
    else:
        return None


def checkTicker(ticker, startDate, endDate):
    hist = utils.getHistoricalData(ticker, startDate, endDate)
    actual = utils.getActualData(ticker)
    result = checkVolumeSpike(ticker, hist, actual)
    return result


if __name__ == "__main__":

    allTickers = utils.getAllTickers(limit=200)
    startDate = utils.getToday(-20)
    endDate = utils.getToday(0)
    results = []
    for ticker in allTickers:
        result = checkTicker(ticker, startDate, endDate)
        if result:
            results += [result]
    dataFrames = []
    newTickers = []
    spottedTickers = [result['ticker'] for result in results]

    dataFrames += [result['dataFrame'] for result in results]

    df = pd.concat(dataFrames)
    now = datetime.datetime.now().strftime('%Y:%m:%d:%H.%M.%S')
    df['timeStr'] = now
예제 #12
0
  def scrape(self):
    today = getToday()
    if self.args.date:
      today = self.args.date
      self.args.download = False # can't set another date and download

    todayClean = re.sub(r'(\d{4}\-\d{2}\-\d{2}).*', r'\1', today)
    htmlFile = self.settings['cacheDir'] + today + '.html'
    listFile = self.settings['namesDir'] + today + '.lst'
    slackChannel = self.settings['slack'].get('channel', None)

    print('Starting %s' % (today, ))
    print('HTML file %s' % (htmlFile, ))
    print('List file %s' % (listFile, ))

    if (self.args.download):
      writeData(
        Downloader().download(self.settings['teamUrl'], self.args.verbose),
        htmlFile
      )

    allFiles = listFiles(self.settings['namesDir'])
    prevListFile = getFilenameBefore(
      [f for f in allFiles if f[-4:] == '.lst'],
      listFile
    )

    print('Prev List file %s' % (prevListFile, ))

    newNameList = HTMLPage(htmlFile).getPeopleNames()
    print('Found %s new names (incl dogs)' % (len(newNameList), ))

    if prevListFile:
      oldNameList = readLines(prevListFile)
      print('Found %s prev names' % (len(oldNameList), ))

      ghosts = getMissingNames(oldNameList, newNameList)
      freshies = getMissingNames(newNameList, oldNameList)
      print('Found %s ghosts' % (len(ghosts), ))
      print('Found %s new Freshies' % (len(freshies), ))

      if self.args.verbose:
        print('%s is a FreshGhost' % (ghosts, ))
        print('%s is fresh' % (freshies, ))

      if self.args.slack:
        if len(ghosts) or (self.args.newbies and len(newbies)):
          print('posting', today, freshies, ghosts, slackChannel)
          postFacesToSlack(
            self.settings['slack']['endpoint'],
            today,
            freshies,
            ghosts,
            slackChannel)
          print('Posted ghosts & freshies to slack channel %s' % (slackChannel, ))

    else:
      print('No prev name list found. Is this the start of time?')
      ghosts = []
      freshies = []

    if self.args.save:
      print('Saving new names list to %s' % (listFile, ))
      writeLines(listFile, newNameList)

      jsonFileReader = open(self.settings['summaryFile'], 'r')
      summaryData = json.load(jsonFileReader)
      summaryData[today] = dict(
        date=todayClean,
        count=len(newNameList),
        additions=len(freshies),
        removals=len(ghosts),
      )
      jsonFileReader.close()

      print('Adding to summary json %s' % (self.settings['summaryFile'], ))
      jsonFileWriter = open(self.settings['summaryFile'], 'w')
      json.dump(summaryData, jsonFileWriter)
      jsonFileWriter.close()

    if self.args.graph:
      print('Building graph')
      jsonFileReader = open(self.settings['summaryFile'], 'r')
      renderGraph(
        self.settings['graphDir'] + todayClean + '.png',
        prepareGraphData(json.load(jsonFileReader), todayClean),
      )

      if self.args.slack:
        postGraphToSlack(
          self.settings['slack']['endpoint'],
          todayClean,
          self.settings['graphURLRoot'] + todayClean + '.png',
          dict(
            date=todayClean,
            count=len(newNameList),
            additions=len(freshies),
            removals=len(ghosts),
          ),
          slackChannel)
        print('Posted graph image to slack channel %s' % (slackChannel, ))

    print('Done')
예제 #13
0
파일: views.py 프로젝트: yrjie/Rghoul
def onDate(request, date=None, page=None):
    if date == None:
        date = utils.getToday()
    if page and page != "lunch" and page != "dinner":
        return HttpResponseNotFound(utils.notFound % request.path_info)
    lunch9, lunch22, dinner9, dinner22 = utils.getFileLists(date)
    lunch9cnt, lunch22cnt, dinner9cnt, dinner22cnt = {}, {}, {}, {}
    folders = utils.getDateList()
    dateObj = utils.getDateObj(date)
    useSp = dateObj > utils.dateSp  # sharepoint
    if not useSp:
        for file in lunch9:
            lunch9cnt[file] = getPicCnt(file)
        for file in lunch22:
            lunch22cnt[file] = getPicCnt(file)
        for file in dinner9:
            dinner9cnt[file] = getPicCnt(file)
        for file in dinner22:
            dinner22cnt[file] = getPicCnt(file)
    showDinner = (dinner9cnt
                  or dinner22cnt) and utils.getNowH() >= utils.dinnerH
    if page == "lunch":
        showDinner = False
    elif page == "dinner":
        showDinner = True
    cmts = []
    allcmts = Comment.objects.order_by("-id")[0:50]
    groupSize = 10
    group = []
    for i, x in enumerate(allcmts):
        if i % groupSize == 0:
            if i > 0:
                cmts.append(group)
            group = []
        group.append(x.context + utils.getPdate(x.date))
    if group:
        cmts.append(group)
    if not useSp:
        return render_to_response(
            "index.html", {
                "folders": folders,
                "date": date,
                "lunch9cnt": lunch9cnt,
                "lunch22cnt": lunch22cnt,
                "dinner9cnt": dinner9cnt,
                "dinner22cnt": dinner22cnt,
                "cmts": cmts,
                "showDinner": showDinner
            })
    isToday = date == utils.getToday()
    lunch9info, lunch22info, dinner9info, dinner22info = {}, {}, {}, {}
    for file in lunch9:
        lunch9info[file] = getDishInfo(file, date)
    for file in lunch22:
        lunch22info[file] = getDishInfo(file, date)
    for file in dinner9:
        dinner9info[file] = getDishInfo(file, date)
    for file in dinner22:
        dinner22info[file] = getDishInfo(file, date)
    meal = ""
    if isToday and (lunch9info or lunch22info or dinner9info or dinner22info):
        if utils.getNowH() >= utils.dinnerH:
            meal = "dinner"
        else:
            meal = "lunch"
    showDinner = (dinner9info
                  or dinner22info) and utils.getNowH() >= utils.dinnerH
    if page == "lunch":
        showDinner = False
    elif page == "dinner":
        showDinner = True
    polls = getOpenPolls()
    dateTtl = dateObj.strftime("%m.%d")
    return render_to_response(
        "indexSp.html", {
            "folders": folders,
            "date": date,
            "meal": meal,
            "lunch9info": lunch9info,
            "lunch22info": lunch22info,
            "dinner9info": dinner9info,
            "dinner22info": dinner22info,
            "cmts": cmts,
            "showDinner": showDinner,
            "polls": polls,
            "dateTtl": dateTtl
        })
예제 #14
0
파일: views.py 프로젝트: yrjie/Rghoul
def onDate(request, date=None, page=None):
    if date == None:
        date = utils.getToday()
    if page and page!="lunch" and page!="dinner":
        return HttpResponseNotFound(utils.notFound % request.path_info)
    lunch9, lunch22, dinner9, dinner22 = utils.getFileLists(date)
    lunch9cnt, lunch22cnt, dinner9cnt, dinner22cnt = {}, {}, {}, {}
    folders = utils.getDateList()
    dateObj = utils.getDateObj(date)
    useSp = dateObj > utils.dateSp  # sharepoint
    if not useSp:
        for file in lunch9:
            lunch9cnt[file] = getPicCnt(file)
        for file in lunch22:
            lunch22cnt[file] = getPicCnt(file)
        for file in dinner9:
            dinner9cnt[file] = getPicCnt(file)
        for file in dinner22:
            dinner22cnt[file] = getPicCnt(file)
    showDinner = (dinner9cnt or dinner22cnt) and utils.getNowH() >= utils.dinnerH
    if page=="lunch":
        showDinner = False
    elif page=="dinner":
        showDinner = True
    cmts = []
    allcmts = Comment.objects.order_by("-id")[0:50]
    groupSize = 10
    group = []
    for i, x in enumerate(allcmts):
        if i%groupSize == 0:
            if i>0:
                cmts.append(group)
            group = []
        group.append(x.context + utils.getPdate(x.date))
    if group:
        cmts.append(group)
    if not useSp:
        return render_to_response("index.html", {"folders":folders, "date":date, 
                                             "lunch9cnt":lunch9cnt, "lunch22cnt":lunch22cnt, 
                                             "dinner9cnt":dinner9cnt, "dinner22cnt":dinner22cnt,
                                             "cmts":cmts, "showDinner":showDinner})
    isToday = date==utils.getToday()
    lunch9info, lunch22info, dinner9info, dinner22info = {}, {}, {}, {}
    for file in lunch9:
        lunch9info[file] = getDishInfo(file, date)
    for file in lunch22:
        lunch22info[file] = getDishInfo(file, date)
    for file in dinner9:
        dinner9info[file] = getDishInfo(file, date)
    for file in dinner22:
        dinner22info[file] = getDishInfo(file, date)
    meal = ""
    if isToday and (lunch9info or lunch22info or dinner9info or dinner22info):
        if utils.getNowH() >= utils.dinnerH:
            meal = "dinner"
        else:
            meal = "lunch"
    showDinner = (dinner9info or dinner22info) and utils.getNowH() >= utils.dinnerH
    if page=="lunch":
        showDinner = False
    elif page=="dinner":
        showDinner = True
    polls = getOpenPolls()
    dateTtl = dateObj.strftime("%m.%d")
    return render_to_response("indexSp.html", {"folders":folders, "date":date, "meal":meal,
                                             "lunch9info":lunch9info, "lunch22info":lunch22info, 
                                             "dinner9info":dinner9info, "dinner22info":dinner22info, 
                                             "cmts":cmts, "showDinner":showDinner,
                                             "polls":polls, "dateTtl":dateTtl})