Example #1
0
def get_date(out, date, type=None, prefix="date_"):
    if date is None:
        return False
    if not type:
        type = underscore(date.get('type'))
    if not type:
        return
    if date is not None:
        out[prefix+type] = date.get('iso-date')
    if (not date.get('iso-date')) and date.text:
        out[prefix+type] = date.text
Example #2
0
def eedate_2_string(date):
    """

    Args:
        date: ee.Date

    Returns:
        string
    """
    str_day = convert_int(str(date.get("day").format().getInfo()))
    str_month = convert_int(str(date.get("month").format().getInfo()))
    str_year = convert_int(str(date.get("year").format().getInfo()))
    return "{}-{}-{}".format(str_year, str_month, str_day)
Example #3
0
def get_table_data_bss(bss_codes, dates):
    details_ = get_details_from_bss(",".join(bss_codes))
    data = []
    if details_ != -1:
        if len(dates) > 0:
            for date in dates:
                data_ = {}
                for code, details in details_.items():
                    result = get_mesure_piezo(
                        code,
                        start_date=date.get("start_date", None),
                        end_date=date.get("end_date", None))
                    if details["code_commune"] not in data_:
                        data_[details["code_commune"]] = {
                            "data": {},
                            "name": details["nom_commune"]
                        }

                    data_[details["code_commune"]]["data"][code] = {
                        "date_debut_mesure": details["date_debut_mesure"],
                        "date_fin_mesure": details["date_fin_mesure"],
                        "mesures": result["mesures"],
                        "count": result["count"]
                    }
                _ = {
                    "data": data_,
                    "start_date": date.get("start_date", None),
                    "end_date": date.get("end_date", None)
                }
                data.append(_)
        else:
            data_ = {}
            for code, details in details_.items():
                result = get_mesure_piezo(code)
                if details["code_commune"] not in data_:
                    data_[details["code_commune"]] = {
                        "data": {},
                        "name": details["nom_commune"]
                    }
                data_[details["code_commune"]]["data"][code] = {
                    "date_debut_mesure": details["date_debut_mesure"],
                    "date_fin_mesure": details["date_fin_mesure"],
                    "mesures": result["mesures"],
                    "count": result["count"]
                }
            _ = {"data": data_}
            data.append(_)

    return data
Example #4
0
 def __init__(self, master, date):
     Frame.__init__(self, master)
     self.pack(side=LEFT)
     self['width'] = 200
     self['height'] = 300
     self['bg'] = 'black'
     self['bd'] = 5
     self.label = Label(self, text=date.get('title'))
     self.label.pack()
     self.lebel_indication = Label(self, text='Текущие')
     self.lebel_indication.pack()
     self.indication = Label(self,
                             text=date.get('indication'),
                             font='arial 24')
     self.indication.pack()
     self.last_pay_date = Label(self,
                                text='Оплачены ' +
                                date.get('last_pay_date'))
     self.last_pay_date.pack()
     self.last_indication = Label(self, text=date.get('indication'))
     self.last_indication.pack()
     self.pay = Label(
         self,
         text='Нужно заплатить ' + str(
             (int(date.get('indication')) -
              int(date.get('last_indication'))) * int(date.get('cost'))) +
         ' Рублей')
     self.pay.pack()
Example #5
0
def generate_url_list(start_date, end_date, city_id=101200101):
    weather_url_list = []
    dates = []
    for year in range(start_date.get('year'), end_date.get('year') + 1):
        if year == end_date.get('year'):
            for month in range(1, start_date.get('month') + 1):
                date = {'year': str(year), 'month': str(month).zfill(2)}
                dates.append(date)
        else:
            for month in range(start_date.get('month'), 12 + 1):
                date = {'year': str(year), 'month': str(month).zfill(2)}
                dates.append(date)
    for date in dates:
        weather_url_list.append(
            base_url.format(year=date.get('year'),
                            date=date.get('year') + date.get('month'),
                            city_id=city_id))
    return weather_url_list
        def recibo():
            txtrecibido.delete("1.0", END)
            x = random.randint(1000000, 99999999)
            randomRef = str(x)
            global url
            url = int(randomRef)
            Recibo_Ref.set("URL" + randomRef)

            txtrecibido.insert(
                END, "Recibo RUC:\t\t\t" + Recibo_Ref.get() + "\t\t" +
                date.get() + "\n")
            txtrecibido.insert(END, "ITEMS:\t\t\t\t\t" + "Costo de items \n\n")
            txtrecibido.insert(END,
                               "Jugo de Mango:\t\t\t\t" + E_Mango.get() + "\n")
            txtrecibido.insert(END,
                               "Jugo de Piña:\t\t\t\t" + E_piña.get() + "\n")
            txtrecibido.insert(END,
                               "Jugo de Fresa:\t\t\t\t" + E_fresa.get() + "\n")
            txtrecibido.insert(
                END, "Jugo de Papaya:\t\t\t\t" + E_papaya.get() + "\n")
            txtrecibido.insert(
                END, "Jugo de Plátano:\t\t\t\t" + E_platano.get() + "\n")
            txtrecibido.insert(END,
                               "Jugo de Kiwi:\t\t\t\t" + E_kiwi.get() + "\n")
            txtrecibido.insert(END,
                               "Surtido:\t\t\t\t" + E_surtido.get() + "\n")
            txtrecibido.insert(END,
                               "Especial:\t\t\t\t" + E_especial.get() + "\n")
            txtrecibido.insert(
                END, "Pastel de chocolate:\t\t\t\t" + E_choco.get() + "\n")
            txtrecibido.insert(
                END, "Pie de manzana/durazno:\t\t\t\t" + E_pie.get() + "\n")
            txtrecibido.insert(END,
                               "Hamburguesa:\t\t\t\t" + E_hamb.get() + "\n")
            txtrecibido.insert(
                END, "Sandwich de pollo:\t\t\t\t" + E_sand.get() + "\n")
            txtrecibido.insert(END,
                               "Bolognesa:\t\t\t\t" + E_bolog.get() + "\n")
            txtrecibido.insert(
                END, "Pie acaramelado de Piña:\t\t\t\t" + E_piñas.get() + "\n")
            txtrecibido.insert(
                END, "Ensalada de fruta:\t\t\t\t" + E_fruta.get() + "\n")
            txtrecibido.insert(END,
                               "Menu del dia:\t\t\t\t" + E_menu.get() + "\n")
            txtrecibido.insert(
                END, "Costos de bebidas:\t\t" + Costodrink.get() +
                "\tIGV:\t\t" + PaidTax.get() + "\n")
            txtrecibido.insert(
                END, "Costos de aperitivos:\t\t" + Costotorta.get() +
                "\tSub Total:\t\t" + SubTotal.get() + "\n")
            txtrecibido.insert(
                END, "Cargo por servicios:\t\t" + Serviciocargo.get() +
                "\tCosto Total:\t\t" + Totalcost.get() + "\n")
 def get_date(self, response):
     date = self.process_xpath(
         response,
         '//div[@id="details"]//div[contains(text(), "RELEASED")]/text()')
     if date:
         date = date.get()
         if "RELEASED" in date:
             date = re.search(r'(\w+ \d{1,2}, \d{4})', date)
             if date:
                 return self.parse_date(date.group(1),
                                        date_formats=['%B %d, %Y'
                                                      ]).isoformat()
     return self.parse_date('today').isoformat()
Example #8
0
def added():
    value = "insert into patient_reg(rid_no,date_reg,pid,name_pat,gender,age,phone,address,disease,sod)values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
    value1 = (no.get(), date.get(), pid.get(), name.get(), gender.get(),
              age.get(), phone.get(), address.get(), disease.get(), sod.get())
    #print(value1)
    mycursor.execute(value, value1)
    mydb.commit()
    value2 = "insert into room_infor(rid_no,name_pat,building,room_type,room_no,room_price)values(%s,%s,%s,%s,%s,%s)"
    value3 = (no.get(), name.get(), building.get(), rtype.get(), rno.get(),
              price.get())
    mycursor.execute(value2, value3)
    mydb.commit()
    pat_reg()
    def crawl(self):

        listings = {}
        location = 'NY, United States'
        offset = 0
        page_count = 0
        page_limit = 25
        found_listings_ids = set()


        search_first_loop = True

        self.cursor.execute('SELECT room_id FROM city_listings')

        listing_dates_data = list()

        room_ids = [e for l in self.cursor.fetchall() for e in l]
        for room_id in room_ids:
            r = self.get(self.availability_url(room_id), referer='https://m.airbnb.com/s/%s' % location)
            try:
                js = json.loads(r.text)
                try:
                    dates_list = js['calendar']['dates']
                except KeyError:
                    print('Could not load dates for room ID ' + room_id)
                    continue
                for date in dates_list:
                    q = {'site': 'Airbnb', 'room_id': room_id}
                    for f in ('date', 'available'):
                        try:
                            q[f] = date[f]
                        except KeyError:
                            print('Passing, could not match ' + f)
                            break
                    q['has_availability'] = q['available']
                    del q['available']
                    q['price'] = date.get('price_native', None)
                    listing_dates_data.append(q)

            except ValueError as e:
                print('Could not load JSON')
                print(r.text)
                continue

        db_fields = ["site", "room_id", "date", "has_availability", "price" ]
        key_fields = ["site", "room_id", "date", "has_availability",]
        
        self.__insert_into_db(db_fields, key_fields, listing_dates_data)
Example #10
0
def wired_out():
	# Make the soup, real quick
	quMath_url = "http://www.wired.com/?s=mathematician"
	page_html = urllib2.urlopen(quMath_url) 
	soup = BeautifulSoup(page_html,"html.parser")

	#Find article titles 
	titles = []
	for art in soup.find_all('h2', {'class': 'title brandon clamp-5'}):
	    titles.append(art.text)

	# Sift for article urls 
	urList=[]
	for urls in soup.find_all('ul', {'class': 'border-t border-micro'}):
		for urls2 in urls.find_all('a'):
			urList.append(urls2.get('href'))

	#Find blurbs
	blurbs = []
	for para in soup.find_all('p', {'class': 'exchange-sm clamp-3 marg-t-micro'}):
	    blurbs.append(para.text)

	dates = []
	for date in soup.find_all('time'):
		dates.append(date.get('pubdate'))

	# gets rid of empty dates
	dates = [x for x in dates if x!=None]

	# date format
	for i in range(len(dates)):
		dates[i]= parse(dates[i])


	# dictionary containing article info
	articleInfo= {'title': None, 'url': None, 'blurb': None, 'date': None, 'shares': None}
	articlesDictList= []
	# puts values into array of dictionaries
	for i in range(len(dates)):
		articleInfo["title"] = titles[i]
		articleInfo["url"] = urList[i]
		articleInfo["blurb"] = blurbs[i]
		articleInfo["date"] = dates[i]
		articlesDictList.append(articleInfo.copy())
		
	# return articles
	return articlesDictList
Example #11
0
    def is_compare_chain_minus(self, code, analyze_at, day_cnt):
        cursor = self.connection.cursor()
        cursor.execute(
            "select date from data.daily_stock ds "
            "where ds.code = %s and ds.date < %s order by ds.id desc limit %s",
            (code, analyze_at, day_cnt))
        dates = cursor.fetchall()

        result = True
        for date in dates:
            cursor.execute(
                "select (ds.close-ds.open) as compare from data.daily_stock ds where ds.code = %s and ds.date = %s",
                (code, date.get('date')))
            compare = cursor.fetchone().get('compare')
            if compare > 0:
                result = False
        return result
Example #12
0
def avito(url):
    lst = []
    page = pagefetcher(url)
    if not page:
        return
    soup = soupmaker(page.text)
    item_table = soup.find_all('div', {'class': 'item_table'})
    for item in item_table:
        title = item.find('a', {'class': 'snippet-link'})
        if not title:
            continue
        else:
            title = title.get('title')
            if BAN_WORD in title:
                continue

        price = item.find('meta', {'itemprop': 'price'})
        price = price.get('content') if price else ''

        address = item.find('span', {'class': 'item-address__string'})
        address = address.text.replace('\n', ' ') if address else ''

        date = item.find('div', {'class': 'snippet-date-info'})
        date = date.get('data-tooltip') if date else ''
        date = get_avito_date(date)

        img = item.find('div', {'class': 'item-slider-image'})
        img = img.img if img else None
        img = img.get('src') if img else ''

        link = item.find('a', {'class': 'item-slider'})
        link = f"https://avito.ru{link.get('href')}" if link else ''

        title = f"{title} {price} {address}"
        dct = dct_validate(name='avito.ru',
                           time=date,
                           title=title,
                           content=title,
                           img=img,
                           link=link)
        #input (dct)
        lst.append(dct)
    return lst
Example #13
0
def get_date_display(date, client):
    """Returns a date expression for a date object.

    Concatenates start and end dates if no date expression exists.

    :param dict date: an ArchivesSpace date

    :returns: date expression for the date object.
    :rtype: str
    """
    date = resolve_to_json(date, client)
    try:
        expression = date["expression"]
    except KeyError:
        if date.get("end"):
            expression = "{0}-{1}".format(date["begin"], date["end"])
        else:
            expression = date["begin"]
    return expression
Example #14
0
    content = content.splitlines()
    for line in content:
        if 'background:#efefde' in line:
            sub_line = ' '.join(line.split()).split('</tr>')
            for part in sub_line:
                if part.startswith('<tr><td '):
                    event_date = part.replace('<tr><td colspan=7 style=\'background:#efefde\'><center><b>', '').replace(
                        '</b></center></td>', '')
                else:
                    if name in part:
                        data = part.replace('<tr><td>', '').split('</td><td>')
                        out = {'Date': event_date, 'Районний підрозділ': data[0], 'Населенний пункт': data[1],
                               'Вулиця': data[2], 'Відкл.уст.': data[3], 'Роботи': data[4],
                               'Час': data[5].replace('</td>', '')}
                        result.append(out)

    return result


if __name__ == '__main__':
    output = check_blackout(date_to, date_from, rp, location)

    for date in output:
        print '\n'
        print 'Дата: ', date.get('Date')
        print 'Районний підрозділ: ', date.get('Районний підрозділ')
        print 'Населенний пункт:', date.get('Населенний пункт')
        print 'Вулиця: ', date.get('Вулиця')
        print 'Відкл.уст.: ', date.get('Відкл.уст.')
        print 'Роботи: ', date.get('Роботи')
        print 'Час: ', date.get('Час')
                       proxies=proxies,
                       cookies=cookies,
                       headers=header)
    full_response = news_pull.text

    article_soup = BeautifulSoup(full_response, 'html.parser')

    content = article_soup.find("input", {"id": "content"})
    content = content.get('value')
    content = strip_tags(content)
    content = clear_character_junk(content)
    title = article_soup.find("input", {"id": "mainTitle"})
    title = title.get('value')
    title = strip_tags(title)
    title = clear_character_junk(title)
    date = article_soup.find("input", {"id": "fCreateDate"})
    date = date.get('value')
    date = strip_tags(date)
    date = clear_character_junk(date)
    if date == now:
        pulled_article_titles.append(title)

    else:
        pass

log_name = "test_kcna_titles.txt"

f = open(log_name, "w+")
for article_title in pulled_article_titles:
    f.write(article_title + "\r\n")
Example #16
0
def edit(request, aktivitet):
    if request.method == 'GET':
        aktivitet = Aktivitet.objects.prefetch_related('municipalities', 'counties').get(id=aktivitet)
        context = {
            'aktivitet': aktivitet,
            'difficulties': Aktivitet.DIFFICULTY_CHOICES,
            'audiences': AktivitetAudience.AUDIENCE_CHOICES,
            'categories': Aktivitet.CATEGORY_CHOICES,
            'all_foreninger': Forening.get_all_sorted(),
            'cabins': Cabin.objects.order_by('name'),
            'admin_user_search_char_length': settings.ADMIN_USER_SEARCH_CHAR_LENGTH,
            'counties': County.typical_objects().order_by('name'),
            'municipalities': Municipality.objects.order_by('name'),
            'omrader': sorted(Omrade.lookup(), key=lambda o: o.navn),
            'now': datetime.now()
        }
        return render(request, 'common/admin/aktiviteter/edit/edit.html', context)
    elif request.method == 'POST':
        errors = False

        aktivitet = Aktivitet.objects.get(id=aktivitet)

        if aktivitet.is_imported():
            # Should only be possible by circumventing client-side restrictions
            return redirect('admin.aktiviteter.views.edit', aktivitet.id)

        if 'code' in request.POST:
            aktivitet.code = request.POST['code']

        if 'title' in request.POST:
            aktivitet.title = request.POST['title']

        if 'description' in request.POST:
            aktivitet.description = request.POST['description']

        if 'difficulty' in request.POST:
            aktivitet.difficulty = request.POST['difficulty']

        if 'audiences' in request.POST:
            aktivitet.audiences = [
                AktivitetAudience.objects.get(name=audience)
                for audience in request.POST.getlist('audiences')
            ]

        if 'category' in request.POST:
            aktivitet.category = request.POST['category']

        if 'category_type' in request.POST:
            aktivitet.category_type = request.POST['category_type']

        if 'publish' in request.POST:
            aktivitet.published = request.POST.get('publish') == 'publish'

        if 'getting_there' in request.POST:
            aktivitet.getting_there = request.POST['getting_there']

        if 'omrader' in request.POST:
            aktivitet.omrader = request.POST.getlist('omrader')

        if 'ntb_id' not in request.POST or request.POST['ntb_id'] == '':
            aktivitet.turforslag = None
        else:
            aktivitet.turforslag = request.POST['ntb_id']

        if aktivitet.published:
            # If published, set the extra relevant fields (otherwise ignore them)
            aktivitet.private = request.POST['private'] == 'private'
            try:
                aktivitet.pub_date = datetime.strptime(request.POST['pub_date'], "%d.%m.%Y").date()
            except ValueError:
                errors = True
                messages.error(request, 'invalid_date_format')

        forening_type, forening_id = request.POST['forening'].split(':')
        if forening_type == 'forening':
            forening = Forening.objects.get(id=forening_id)
            if not forening in request.user.children_foreninger():
                raise PermissionDenied
            aktivitet.forening = forening
        elif forening_type == 'cabin':
            aktivitet.forening_cabin = Cabin.objects.get(id=forening_id)
        else:
            raise PermissionDenied

        if 'co_foreninger[]' in request.POST and request.POST['co_foreninger[]'] != '':
            co_foreninger = []
            co_foreninger_cabin = []
            for co_forening in request.POST.getlist('co_foreninger[]'):
                type, id = co_forening.split(':')
                if type == 'forening':
                    co_foreninger.append(id)
                elif type == 'cabin':
                    co_foreninger_cabin.append(id)
                else:
                    raise PermissionDenied

            aktivitet.co_foreninger = co_foreninger
            aktivitet.co_foreninger_cabin = co_foreninger_cabin
        else:
            aktivitet.co_foreninger = []
            aktivitet.co_foreninger_cabin = []

        if 'latlng' in request.POST:
            latlng = request.POST['latlng'].split(',')
            if len(latlng) == 2:
                aktivitet.start_point = Point(float(latlng[0]), float(latlng[1]))

        aktivitet.save()

        aktivitet.counties = request.POST.getlist('counties')
        aktivitet.municipalities = request.POST.getlist('municipalities')

        aktivitet.category_tags.clear()
        if 'category_tags' in request.POST and request.POST['category_tags'] != '':
            for tag in request.POST.getlist('category_tags'):
                obj, created = Tag.objects.get_or_create(name=tag)
                aktivitet.category_tags.add(obj)

        aktivitet.images.all().delete()
        for i, image in parse_html_array(request.POST, 'images').items():
            AktivitetImage(
                aktivitet=aktivitet,
                url=image['url'],
                text=image['description'],
                photographer=image['photographer'],
                order=i
            ).save()

        dates = parse_html_array(request.POST, 'dates').items()

        # Remove the date objects that were explicitly deleted (checks and verifications are done
        # client-side). Verify that those that would be implicitly deleted (by not being POSTed for
        # editing) match those explicitly POSTed.
        date_ids = [int(d['id']) for k, d in dates if d['id'] != '']
        implicit_del = set([date.id for date in aktivitet.dates.all() if date.id not in date_ids])

        if len(implicit_del) > 0:
            # Better to raise an exception and not delete anything. The user will be confused and
            # lose edits, but we'll get a report and hopefully be able to fix this, if it ever
            # happens.
            raise Exception("Implicit delete of AktivitetDate is strictly forbidden!")

        for i, date in dates:
            if date['id'] != '':
                # @TODO Check if this can be exploited. Can you hijack another trip's date by
                # setting an arbitrary ID in the date['id'] field?
                model = AktivitetDate.objects.get(id=date['id'])
            else:
                model = AktivitetDate(aktivitet=aktivitet)

            # @TODO for existing dates; if model.start_date > now; dissalow editing.

            # Explicit delete of dates
            if date['status'] == 'delete':
                if date['id'] != '':
                    if model.participant_count() > 0:
                        raise Exception("Date with participants can not be deleted!")
                    model.delete()
                continue

            try:
                if not date['start_time']: date['start_time'] = '08:00'
                if not date['end_time']: date['end_time'] = '16:00'

                # @TODO check start_time > now
                model.start_date = datetime.strptime(
                    "%s %s" % (date['start_date'], date['start_time']),
                    "%d.%m.%Y %H:%M"
                )

                # @TODO check end_time > start_time
                model.end_date = datetime.strptime(
                    "%s %s" % (date['end_date'], date['end_time']),
                    "%d.%m.%Y %H:%M"
                )

                # @TODO check start_date > meeting_time
                if date['start_date'] and date['meeting_time']:
                    model.meeting_time = datetime.strptime(
                        "%s %s" % (date['start_date'], date['meeting_time']),
                        "%d.%m.%Y %H:%M"
                    )

                if not date['signup_method'] or date['signup_method'] == 'none':
                    # To the next maintainer. This block indicates that a date does not allow
                    # signup. However, keep in mind that this might be an existing date with
                    # participants. Hence, do not set model.participant to None event though it
                    # might be tempting!

                    model.signup_enabled = False
                    model.signup_start = None
                    model.signup_deadline = None
                    model.cancel_deadline = None

                elif date['signup_method'] == 'normal' or date['signup_method'] == 'simple':
                    model.signup_enabled = True

                    if date.get('max_participants_limited'):
                        model.max_participants = date['max_participants']
                    else:
                        model.max_participants = None

                    if date.get('no_signup_start') == '1':
                        model.signup_start = None
                    else:
                        model.signup_start = datetime.strptime(
                            date['signup_start'],
                            "%d.%m.%Y",
                        ).date()

                    if 'no_signup_deadline' in date and date['no_signup_deadline'] == '1':
                        model.signup_deadline = None
                    elif 'signup_deadline' in date and date['signup_deadline'] != '':
                        model.signup_deadline = datetime.strptime(
                            date['signup_deadline'],
                            "%d.%m.%Y",
                        ).date()

                    if 'no_cancel_deadline' in date and date['no_cancel_deadline'] == '1':
                        model.cancel_deadline = None
                    elif 'cancel_deadline' in date and date['cancel_deadline'] != '':
                        model.cancel_deadline = datetime.strptime(
                            date['cancel_deadline'], "%d.%m.%Y"
                        ).date()

                else:
                    raise Exception("Unrecognized POST value for signup_method field")

            except ValueError:
                errors = True
                messages.error(request, 'invalid_date_format')
                return redirect('admin.aktiviteter.views.edit', aktivitet.id)

            # Note that simple signup is currently disabled and due to be removed
            model.signup_simple_allowed = False
            model.meeting_place = date['meeting_place']
            model.contact_type = date['contact_type']
            model.contact_custom_name = date['contact_custom_name']
            model.contact_custom_phone = date['contact_custom_phone']
            model.contact_custom_email = date['contact_custom_email']
            model.should_have_turleder = date.get('should_have_turleder') == '1'
            model.save()

            if date.get('should_have_turleder') == '1':
                # We need to specify the key for this particular field because the parse_html_array
                # function does not properly parse multidimensional arrays.
                key = 'dates[%s][turleder][]' % i
                if key in request.POST and request.POST[key] != '':
                    model.turledere = request.POST.getlist(key)
            else:
                model.turledere = []

        if not errors:
            messages.info(request, 'save_success')

        if json.loads(request.POST['preview']):
            return redirect('admin.aktiviteter.views.preview', aktivitet.id)
        else:
            return redirect('admin.aktiviteter.views.edit', aktivitet.id)
Example #17
0
def get_table_data_locations(coms_to_keep, deps_to_keep, regs_to_keep,
                             dates_to_keep):
    data_ = []
    stations = {}
    if len(dates_to_keep) > 0:
        for date in dates_to_keep:
            data = {}
            for gran, gran_dict in {
                    "commune": coms_to_keep,
                    "departement": deps_to_keep,
                    "region": regs_to_keep
            }.items():
                for loc, details in gran_dict.items():
                    data[loc] = {}
                    code = details.get("codesDepartements", loc)
                    bss = insee_to_bss(code, gran)
                    stations[loc] = {}
                    if bss == -1:
                        data[loc]["data"] = -1
                        data[loc]["name"] = details['nom']
                        stations[loc]["nb_stations"] = 0
                        stations[loc]["stations"] = []
                        stations[loc]["name"] = details['nom']
                    else:
                        for station in bss:
                            result = get_mesure_piezo(
                                station,
                                start_date=date.get("start_date", None),
                                end_date=date.get("end_date", None))
                            bss[station]["mesures"] = result["mesures"]
                            bss[station]["count"] = result["count"]

                        data[loc]["data"] = bss
                        data[loc]["name"] = details['nom']

                        stations[loc]["nb_stations"] = len(bss)
                        stations[loc]["stations"] = list(bss.keys())
                        stations[loc]["name"] = details['nom']

            _ = {
                "data": data,
                "start_date": date.get("start_date", None),
                "end_date": date.get("end_date", None)
            }
            data_.append(_)
    else:
        data = {}
        for gran, gran_dict in {
                "commune": coms_to_keep,
                "departement": deps_to_keep,
                "region": regs_to_keep
        }.items():
            for loc, details in gran_dict.items():
                data[loc] = {}
                code = details.get("codesDepartements", loc)
                bss = insee_to_bss(code, gran)
                stations[loc] = {}
                if bss == -1:
                    data[loc]["data"] = -1
                    data[loc]["name"] = details['nom']
                    stations[loc]["nb_stations"] = 0
                    stations[loc]["stations"] = []
                    stations[loc]["name"] = details['nom']
                else:
                    for station in bss:
                        result = get_mesure_piezo(station)
                        bss[station]["mesures"] = result["mesures"]
                        bss[station]["count"] = result["count"]

                    data[loc]["data"] = bss
                    data[loc]["name"] = details['nom']
                    stations[loc]["nb_stations"] = len(bss)
                    stations[loc]["stations"] = list(bss.keys())
                    stations[loc]["name"] = details['nom']
        _ = {"data": data}
        data_.append(_)

    return data_, stations
            def sendMailLater():
                senderFinal = myMail.get()
                passwordFinal = password.get()
                recieverFinal = otherMail.get()
                subjectFinal = subject.get()
                bodyFinal = body.get("1.0", END)
                dateFinal = date.get()
                timeFinal = time.get()
                window.destroy()
                window2.destroy()
                window3.destroy()
                try:
                    x = sendEmailInTime(senderFinal, passwordFinal,
                                        recieverFinal, subjectFinal, bodyFinal,
                                        getFile.fileName, dateFinal, timeFinal)
                except:
                    x = sendEmailInTime(senderFinal, passwordFinal,
                                        recieverFinal, subjectFinal, bodyFinal,
                                        '0', dateFinal, timeFinal)
                if (x == 'dateFormat'):
                    lll.pack_forget()
                    ll.pack_forget()
                    l.pack_forget()
                    MailSentLabel = Label(
                        topFrame,
                        text="you you have entered a wrong date format")
                    MailSentLabel.config(foreground='#8BD8BD',
                                         background='#243665',
                                         font=('times', 30, 'bold'))
                    MailSentLabel.pack()
                    thankYouLabel = Label(topFrame, text="email not sent")
                    thankYouLabel.config(foreground='#8BD8BD',
                                         background='#243665',
                                         font=('times', 30, 'bold'))
                    thankYouLabel.pack()
                    seeYouLabel = Label(topFrame, text="please try again")
                    seeYouLabel.config(foreground='#8BD8BD',
                                       background='#243665',
                                       font=('times', 30, 'bold'))
                    seeYouLabel.pack()

                elif (x == 'timeFormat'):
                    lll.pack_forget()
                    ll.pack_forget()
                    l.pack_forget()
                    MailSentLabel = Label(
                        topFrame,
                        text="you you have entered a wrong time format")
                    MailSentLabel.config(foreground='#8BD8BD',
                                         background='#243665',
                                         font=('times', 30, 'bold'))
                    MailSentLabel.pack()
                    thankYouLabel = Label(topFrame, text="email not sent")
                    thankYouLabel.config(foreground='#8BD8BD',
                                         background='#243665',
                                         font=('times', 30, 'bold'))
                    thankYouLabel.pack()
                    seeYouLabel = Label(topFrame, text="please try again")
                    seeYouLabel.config(foreground='#8BD8BD',
                                       background='#243665',
                                       font=('times', 30, 'bold'))
                    seeYouLabel.pack()

                elif (x == 'past'):
                    lll.pack_forget()
                    ll.pack_forget()
                    l.pack_forget()
                    root.geometry("1000x300")
                    MailNotSentLabel = Label(
                        topFrame,
                        text=
                        "“You can't go back and change the beginning,but you")
                    MailNotSentLabel.config(foreground='#8BD8BD',
                                            background='#243665',
                                            font=('times', 30, 'bold'))
                    MailNotSentLabel.pack()
                    MailNotSentLabel = Label(
                        topFrame,
                        text="can start where you are and change the ending.”")
                    MailNotSentLabel.config(foreground='#8BD8BD',
                                            background='#243665',
                                            font=('times', 30, 'bold'))
                    MailNotSentLabel.pack()
                    seeYouLabel = Label(topFrame, text="― C. S. Lewis")
                    seeYouLabel.config(foreground='#8BD8BD',
                                       background='#243665',
                                       font=('times', 30, 'bold'))
                    seeYouLabel.pack()
                    seeYouLabel = Label(
                        topFrame,
                        text="we are sorry we can not do anything the past time"
                    )
                    seeYouLabel.config(foreground='#8BD8BD',
                                       background='#243665',
                                       font=('times', 30, 'bold'))
                    seeYouLabel.pack()
                    seeYouLabel = Label(
                        topFrame,
                        text=
                        "please try again and enter a date and time in the future"
                    )
                    seeYouLabel.config(foreground='#8BD8BD',
                                       background='#243665',
                                       font=('times', 30, 'bold'))
                    seeYouLabel.pack()

                elif (x == 'notSent'):
                    lll.pack_forget()
                    ll.pack_forget()
                    l.pack_forget()
                    MailNotSentLabel = Label(topFrame, text="mail not sent")
                    MailNotSentLabel.config(foreground='#8BD8BD',
                                            background='#243665',
                                            font=('times', 30, 'bold'))
                    MailNotSentLabel.pack()
                    seeYouLabel = Label(
                        topFrame,
                        text="please check the entered data and try again")
                    seeYouLabel.config(foreground='#8BD8BD',
                                       background='#243665',
                                       font=('times', 30, 'bold'))
                    seeYouLabel.pack()

                elif (x == 'sent'):
                    lll.pack_forget()
                    ll.pack_forget()
                    l.pack_forget()
                    MailSentLabel = Label(topFrame,
                                          text="mail sent successfully")
                    MailSentLabel.config(foreground='#8BD8BD',
                                         background='#243665',
                                         font=('times', 30, 'bold'))
                    MailSentLabel.pack()
                    thankYouLabel = Label(
                        topFrame, text="thank you for using our program")
                    thankYouLabel.config(foreground='#8BD8BD',
                                         background='#243665',
                                         font=('times', 30, 'bold'))
                    thankYouLabel.pack()
                    seeYouLabel = Label(topFrame, text="see you")
                    seeYouLabel.config(foreground='#8BD8BD',
                                       background='#243665',
                                       font=('times', 30, 'bold'))
                    seeYouLabel.pack()
Example #19
0
import os.path
from datetime import date
 
consumer_key = ''
consumer_secret = ''
user_key = ''
user_secret = ''
jsondir = 'fitbit-json/'
# your user_id, you can get from URL for your profile
uid=''
# actually the first day that you started using fitbit in the format YYYY-MM-DD
end_date=''

d = date.today()
today = str(d.isoformat())
 
authd_client = fitbit.Fitbit(consumer_key, consumer_secret, user_key=user_key, user_secret=user_secret)

max_step_stats = authd_client.time_series('activities/steps',user_id=uid,end_date=end_date,base_date='today')
stepsjson = json.loads(json.dumps(max_step_stats))

for key,value in stepsjson.iteritems():
	for date in value:
		day = date.get('dateTime')
		jsonfile = jsondir + day + ".json"
		if not os.path.isfile(jsonfile) and day != today:
			file = open(jsonfile,'w+')
			json.dump(date,file)
			file.close()

def get_planning_master_data(filters=None):
    filters = json.loads(filters)
    data = dict()
    precision = frappe.db.get_singles_value('System Settings',
                                            'float_precision')
    planning_master = filters.get("planning_master")
    # fetch date_data
    date_data = get_date_data(planning_master)

    data.update({
        'date_data':
        [(pmi.get('date')).strftime('%d-%m-%Y') for pmi in date_data]
    })

    # fetch date_data_with_amount
    date_wise_planning_details = date_wise_planning_master(planning_master)

    data.update({'date_data_with_amount': date_wise_planning_details})

    company = frappe.db.get_single_value("Global Defaults", 'default_company')
    # fetch warehouse list from medtech settings
    fg_warehouse_list = get_warehouses()
    ohs_dict = get_current_stock(fg_warehouse_list)

    # fetch planning_data from planning_master item
    planning_data = get_planning_data(planning_master)

    for row in date_wise_planning_details:
        for item in planning_data:
            if row.item_code == item.item_code:
                item.update({row.get('date').strftime('%d-%m-%Y'): row.amount})

    item_dict = dict()
    final_dict = dict()

    # fetch raw materials data from BOM and stock data
    for item in planning_data:
        bom_data = get_bom_data(item.get('bom'))
        item.update({'bom_data': bom_data})

    item_details = {item.item_code: item for item in planning_data}
    remaining_dict = dict()
    check_date = dict()
    for date in date_wise_planning_details:
        fg_detail = item_details.get(date.get('item_code'))

        for raw in fg_detail.get('bom_data'):
            required_qty = raw.get('stock_qty') * date.get('amount')

            if raw.get('item_code') not in remaining_dict:
                current_stock = ohs_dict.get(raw.get('item_code')) or 0
                stock_expected = get_expected_stock(raw.get('item_code'),
                                                    date.get('date'))
                stock_exp = stock_expected[0].get(
                    "qty") if stock_expected else 0
                virtual_stock = current_stock + stock_exp

                remaining_qty = virtual_stock - required_qty

                remaining_dict[raw.get(
                    'item_code')] = remaining_qty if remaining_qty > 0 else 0
                raw[date.get('date').strftime('%d-%m-%Y')] = flt(
                    remaining_qty, precision) if remaining_qty < 0 else flt(
                        required_qty, precision)
                check_date[raw.get('item_code')] = date.get('date')
            else:
                if date.get('date') == check_date.get(raw.get('item_code')):
                    virtual_stock = remaining_dict.get(raw.get('item_code'))
                else:
                    stock_expected = get_expected_stock(
                        raw.get('item_code'), date.get('date'))
                    stock_exp = stock_expected[0].get(
                        "qty") if stock_expected else 0
                    check_date[raw.get('item_code')] = date.get('date')
                    virtual_stock = stock_exp + remaining_dict.get(
                        raw.get('item_code'))

                remaining_qty = virtual_stock - required_qty

                remaining_dict[raw.get(
                    'item_code')] = remaining_qty if remaining_qty > 0 else 0
                raw[date.get('date').strftime('%d-%m-%Y')] = flt(
                    remaining_qty, precision) if remaining_qty < 0 else flt(
                        required_qty, precision)

    data.update({'planning_data': item_details})
    final_data = data
    path = 'medtech_bpa/medtech_bpa/page/plan_availability/plan_availability.html'
    html = frappe.render_template(path, {'data': data})
    return {'html': html, 'data': final_data}