Exemplo n.º 1
0
def single(request, slug):
    try:
        news = News.objects.get(slug=slug)
        advertise = Advertising.objects.order_by('-timestamp')
        all_news = News.objects.order_by('-published_at')[:4]
        news_pd = News.objects.get(slug=slug).published_at
        day = news_pd.day
        year = news_pd.year
        month = news_pd.month
        if len(str(month)) == 1:
            month = "0" + str(month)
            month = int(month)
        if len(str(day)) == 1:
            day = "0" + str(day)
            day = int(day)
        pub_date_ad = NepaliDate(year, month, day)
        np_date = NepaliDate.from_date(pub_date_ad)
        x = np_date.strftime('%A %d %B  %Y')

        context = {
            'news': news,
            'advertise': advertise,
            'all_news': all_news,
            'x': x
        }
        template = 'newsportalapp/single.html'
        return render(request, template, context)

    except:
        raise Http404
Exemplo n.º 2
0
def all(request):
    news = News.objects.order_by('-published_at')
    business_news = Business_News.objects.order_by('-published_at')
    news_portal = News.objects.order_by('-published_at')
    covid_news = Covid_News.objects.order_by('-published_at')
    lifestyle_news = Lifestyle_News.objects.order_by('-published_at')
    tech_news = Tech_News.objects.order_by('-published_at')
    entertainment_news = Entertainment_News.objects.order_by('-published_at')
    sports_news = Sports_News.objects.order_by('-published_at')
    trending_news = Trending_News.objects.order_by('-published_at')
    advertise = Advertising.objects.order_by('-timestamp')
    nep_date = NepaliDate.today()
    now = datetime.datetime.now()

    context = {
        'news': news,
        'business_news': business_news,
        'news_portal': news_portal,
        'covid_news': covid_news,
        'lifestyle_news': lifestyle_news,
        'tech_news': tech_news,
        'entertainment_news': entertainment_news,
        'sports_news': sports_news,
        'trending_news': trending_news,
        'advertise': advertise,
        'nep_date': nep_date,
        'now': now
    }

    template = 'newsportalapp/all.html'
    return render(request, template, context)
Exemplo n.º 3
0
    def get_initial(self):
        date = self.get_object().date
        np_date = str(NepaliDate.to_nepali_date(date).strfdate("%Y-%m-%d"))

        initial_data = {'date': np_date}

        return initial_data
Exemplo n.º 4
0
    def get_next_month(self):
        '''
            return the next month first day

            Example:
                if 2077-5-23 then it return 2077-6-1
        '''
        if self.np_date.month == 12:
            try:
                next_month = NepaliDate(self.np_date.year + 1, 1, 1)
            except ValueError:
                raise Http404("Date out of range")
            pass
        else:
            next_month = NepaliDate(self.np_date.year, self.np_date.month + 1,
                                    1)
        return next_month
Exemplo n.º 5
0
 def get_month_first_day(self, date=None):
     '''
         return the first date of the np_date passed as an argument
         
         Example:
             if 2077-5-23 then it return 2077-5-01
     '''
     return NepaliDate(self.np_date.year, self.np_date.month, 1)
Exemplo n.º 6
0
 def __init__(self, date, *args, **kwargs):
     '''
         date must be of type nepali_date.date.NepaliDate
     '''
     if not isinstance(date, datetime.date):
         raise ValueError("Date must be instance of datetime.date")
     date_in_bs = NepaliDate.to_nepali_date(date)
     self.np_date = date_in_bs
Exemplo n.º 7
0
def bs_to_ad(date_in_bs):
    '''
     date must be in format: yyyy-mm-dd in BS
     Split the date string and convert to english date as date object
    '''
    year, month, day = split_date(date_in_bs)
    en_date = NepaliDate(year, month, day).to_english_date()
    return en_date
Exemplo n.º 8
0
def all(request):
    news = Lifestyle_News.objects.order_by('-published_at')
    nep_date = NepaliDate.today()
    now = datetime.datetime.now()

    context = {'news': news, 'nep_date': nep_date, 'now':now}
    template = 'lifestyle/all.html'
    return render(request, template, context)
Exemplo n.º 9
0
 def get_context_data(self, **kwargs):
     context = super(TransactionCreateView, self).get_context_data(**kwargs)
     context['member'] = self.get_member()
     query = self.get_member().transaction_set.last()
     if query is not None:
         date = query.date
         nepali_date = NepaliDate.to_nepali_date(date)
         context['last_paid_date'] = nepali_date
     return context
Exemplo n.º 10
0
def all(request):
    covid_news = Covid_News.objects.all()
    advertise = Advertising.objects.order_by('-timestamp')
    nep_date = NepaliDate.today()
    now = datetime.datetime.now()

    context = {'covid_news': covid_news, 'advertise': advertise, 'nep_date': nep_date, 'now':now}
    template = 'covid/all.html'
    return render(request, template, context)
Exemplo n.º 11
0
 def getDate(self, input_nep_date):
     nep_date = input_nep_date.split()
     yy = nep_date[0]
     mm = nep_date[1]
     dd = nep_date[2]
     nep_date = yy+'/'+self.month_mapping[mm]+'/'+dd
     nep_date = NepaliDate.strpdate(nep_date, '%Y/%m/%d')
     eng_date = nep_date.to_english_date().strftime('%m/%d/%Y')
     nep_date = nep_date.strfdate('%Y/%m/%d')
     return (nep_date, eng_date)
Exemplo n.º 12
0
def all(request):
    news = Tech_News.objects.order_by('-published_at')
    advertise = Advertising.objects.order_by('-timestamp')
    nep_date = NepaliDate.today()
    now = datetime.datetime.now()
    context = {
        'news': news,
        'advertise': advertise,
        'nep_date': nep_date,
        'now': now
    }
    template = 'tech/all.html'
    return render(request, template, context)
Exemplo n.º 13
0
def single(request, slug):
    try:
        news = Covid_News.objects.get(slug=slug)
        all_news = Covid_News.objects.order_by('-published_at')[:4]
        advertise = Advertising.objects.order_by('-timestamp')
        nep_date = NepaliDate.today()
        now = datetime.datetime.now()

        context = {'news': news, 'advertise': advertise, 'all_news':all_news, 'nep_date': nep_date, 'now':now}
        template = 'covid/single.html'
        return render(request, template, context)

    except:
        raise Http404
Exemplo n.º 14
0
                month = int(data["url"].split("/")[-2])
                id_ = data["id"]
                if month not in {8, 9, 10}:
                    print("filtered out article ", data["url"])
                    continue
                if id_ in ids:
                    print("duplicate ")
                    continue
                date_nep = data["date_nepali"].split()[:3]
                yy = "".join([str(digit(c)) for c in date_nep[0]])
                if int(yy) < 2076:
                    print("filtered out article from year ", yy)
                    continue
                dd = "".join([str(digit(c)) for c in date_nep[2]])
                mm = month_map[date_nep[1]]
                nd = NepaliDate(yy, mm, dd, lang='nep')

                # print(date_nep, nd)
                # sys.exit(-1)
                data["date_english"] = nd.to_english_date().strftime(
                    "%Y/%-m/%d")
                data["title"] = data["title"].replace(u'\xa0', u' ')
                data["subtitle"] = data["subtitle"].replace(u'\xa0', u' ')
                data["description"] = data["description"].replace(
                    u'\xa0', u' ')
                data["source"] = "onlinekhabar"
                data["category"] = data["category"].split("/")[-1]
                # data['category'] = cat_map[data["category"].split("/")[-1]]
                cats.add(data["category"])
                outfile.write(json.dumps(data) + "\n")
                ids.add(id_)
Exemplo n.º 15
0
def monthly_details(request, id, term, vat=False): 
    customer = Customer.objects.get(id =id)
    opening = OpeningBalance.objects.get(term__id = term, customer = customer)
    nep_start = NepaliDate.to_nepali_date(opening.term.start_date)
    nep_end = NepaliDate.to_nepali_date(opening.term.end_date)
    if NepaliDate.today()< nep_end:
        nep_end = NepaliDate.today()
    all_calendar = pd.read_csv(nepali_datetime.calendar_file.name, index_col = 0)
    
    current_year = int(nep_start.year)
    current_month = int(nep_start.month)
    i = True
    titles = []
    openings = []
    sales = []
    payments = []
    id_tags = []
    opening_dates = []

    while (i):
        if current_month == 1:
            prev_month = 12
            prev_year = current_year - 1
        else:
            prev_month = current_month - 1
            prev_year = current_year

        
        year_calendar = all_calendar.loc[current_year]
        titles.append('%s:%s' % (current_year, year_calendar.index[current_month-1]))
        month_days = int(year_calendar[current_month-1])
        prev_month_days = int(year_calendar[prev_month-1])
        
        start_day = NepaliDate(prev_year, prev_month, prev_month_days).to_english_date()
        end_day = NepaliDate(current_year, current_month, month_days).to_english_date()
        opening_dates.append(start_day)
        monthly_opening = opening.amount + sum(opening.sales_until(start_day)) - sum(opening.payments_until(start_day))
        monthly_invoices = Invoice.objects.filter(
            Q(date__gte = start_day) & Q(date__lte = end_day) & Q(issued_for=customer)
        ).filter(is_vat=vat)
        monthly_payments = Payment.objects.filter(
            Q(date__gte=start_day) & Q(date__lte=end_day) & Q(Q(term__isnull=True) | Q(term__id=term)) & Q(customer=customer)
        )
        
        i, current_month, current_year = update_loop(i, current_month, current_year, nep_end)
        sales.append(monthly_invoices)
        if vat:
            payments.append([])
            openings.append(0)
        else:
            payments.append(monthly_payments)
            openings.append(monthly_opening)
        id_tags.append('%s%s'%(current_year, current_month))

    context = {
        'page_title': customer.name,
        'titles':titles, 'openings': openings, 'sales': sales, 'debits':payments, 'ids': id_tags,
        # 'titles_ids': zip(titles, id_tags),
        'accounts': zip(id_tags, openings, opening_dates, sales, payments, titles),
        "vat": vat
    }
    return render(request, 'invoice/monthly_details.html', context=context)
Exemplo n.º 16
0
def term_monthly_details(request, term, vat=False): 
    opening_bals = OpeningBalance.objects.filter(term__id = term)
    opening_term = Term.objects.get(id=term)
    monthly_opening = sum(opening_bals.values_list('amount', flat=True))
    nep_start = NepaliDate.to_nepali_date(opening_term.start_date)
    nep_end = NepaliDate.to_nepali_date(opening_term.end_date)
    if NepaliDate.today()< nep_end:
        nep_end = NepaliDate.today()
    all_calendar = pd.read_csv(nepali_datetime.calendar_file.name, index_col = 0)
    
    current_year = int(nep_start.year)
    current_month = int(nep_start.month)
    i = True
    titles = []
    openings = []
    sales = []
    payments = []
    id_tags = []
    opening_dates = []
    cash_payments = []

    while (i):
        if current_month == 1:
            prev_month = 12
            prev_year = current_year - 1
        else:
            prev_month = current_month - 1
            prev_year = current_year

        
        year_calendar = all_calendar.loc[current_year]
        titles.append('%s:%s' % (current_year, year_calendar.index[current_month-1]))
        month_days = int(year_calendar[current_month-1])
        prev_month_days = int(year_calendar[prev_month-1])
        
        start_day = NepaliDate(current_year, current_month, 1).to_english_date()
        end_day = NepaliDate(current_year, current_month, month_days).to_english_date()
        opening_dates.append(start_day)
        monthly_invoices = Invoice.objects.filter(
            Q(date__gte = start_day) & Q(date__lte = end_day) 
        ).filter(is_vat=vat).prefetch_related('issued_for')
        monthly_payments = Payment.objects.filter(
            Q(date__gte=start_day) & Q(date__lte=end_day) & Q(Q(term__isnull=True) | Q(term__id=term))
        ).prefetch_related('customer')
        
        i, current_month, current_year = update_loop(i, current_month, current_year, nep_end)
        if vat:
            payments.append([])
            monthly_opening = 0
            openings.append(0)
        else:
            payments.append(monthly_payments)
            openings.append(monthly_opening)
            monthly_opening += sum(monthly_invoices.values_list('total', flat=True)) - sum(monthly_payments.values_list('amount', flat=True)) - sum(monthly_invoices.values_list('paid_amount', flat=True))
        sales.append(monthly_invoices)
        
        id_tags.append('%s%s'%(current_year, current_month))
        cash_payments.append({'amount':sum(monthly_invoices.values_list('paid_amount', flat=True)), 'date': end_day})

    context = {
        'page_title': "Monthly Summary",
        'titles':titles, 'openings': openings, 'sales': sales, 'debits':payments, 'ids': id_tags,
        'titles_ids': zip(titles, id_tags),
        'accounts': zip(id_tags, openings, opening_dates, sales, payments, titles, cash_payments), 
        "vat": vat
    }
    return render(request, 'invoice/monthly_details_term.html', context=context)
Exemplo n.º 17
0
import re
import os
import datetime

from nepali_date import NepaliDate

from get_event import GetPageContent
from set_event import SetSlackStatus

TODAY = NepaliDate.today().isoformat()

DOMAIN = 'www.hamropatro.com'
PATH = "/date/{0}".format(re.sub(r"\b0", "", TODAY))
TAG = 'title'

AUTHORIZATION = os.getenv('BEARER_AUTH_KEY', None)


def get_left_time():
    today_date = datetime.datetime.combine(datetime.date.today(),
                                           datetime.datetime.max.time())

    epoch = datetime.datetime.utcfromtimestamp(0)
    total_utc = (today_date - epoch).total_seconds()

    return total_utc + datetime.timedelta(hours=-5,
                                          minutes=-45).total_seconds()


def set_my_slack_status():
    page_content = GetPageContent(DOMAIN, PATH, TAG)
Exemplo n.º 18
0
def nepali_date(value, arg):
    nepali_date = NepaliDate.to_nepali_date(value)
    formatted_nepali_date = nepali_date.strfdate(arg)
    return formatted_nepali_date
Exemplo n.º 19
0
def convert_to_nepali(date):
    en_date = datetime.datetime.strptime(date, "%Y-%m-%d").date()
    nepali_date = NepaliDate.to_nepali_date(en_date)
    return nepali_date
Exemplo n.º 20
0
def individual_transaction_to_excel(request, member_id, start_date, end_date):
    response = HttpResponse(content_type="application/ms-excel")
    response['Content-Disposition'] = 'attachment; filename="kosh.xls"'

    wb = xlwt.Workbook(encoding='utf-8')
    ws = wb.add_sheet('Individual_Transactions')

    row_num = 0

    font_style = xlwt.XFStyle()
    font_style.font.bold = True

    member = get_object_or_404(Member, pk=member_id)

    ws.write(row_num, 0, "Member's Name", font_style)
    ws.write(row_num, 1, member.name, font_style)

    row_num += 1
    ws.write(row_num, 0, 'Number of Share', font_style)
    ws.write(row_num, 1, member.number_of_share, font_style)

    row_num += 1
    ws.write(row_num, 0, 'Total Saving', font_style)
    ws.write(row_num, 1, member.membersaving.amount, font_style)

    row_num += 1
    ws.write(row_num, 0, 'Total Loan Amount', font_style)
    ws.write(row_num, 1, member.loan.amount, font_style)

    row_num += 1
    row_num += 1

    columns = [
        'Date',
        'Previous Month Loan',
        'Monthly Saving',
        'Loan Amount Paid',
        'Interest',
        'Fine',
        'Others',
        'Total Amount Paid',
        'Remaining Loan Amount',
        'Additional Loan Amount',
        'Total Loan Amount',
    ]

    for col_num, column in enumerate(columns):
        ws.write(row_num, col_num, column, font_style)

    font_style = xlwt.XFStyle()

    from_date = datetime.strptime(start_date, '%Y-%m-%d')
    to_date = datetime.strptime(end_date, '%Y-%m-%d')
    transactions = Transaction.objects.filter(member=member,
                                              date__range=(from_date, to_date))
    members = Member.objects.all().order_by('membership_id')

    for transaction in transactions:
        transaction_nepali_date = NepaliDate.to_nepali_date(transaction.date)
        transaction_strdate_in_bs = transaction_nepali_date.strfdate(
            '%Y-%m-%d')
        row_num += 1
        ws.write(row_num, 0, transaction_strdate_in_bs, font_style)
        ws.write(row_num, 1, transaction.previous_month_loan, font_style)
        ws.write(row_num, 2, transaction.monthly_saving, font_style)
        ws.write(row_num, 3, transaction.loan_amount_paid, font_style)
        ws.write(row_num, 4, transaction.interest, font_style)
        ws.write(row_num, 5, transaction.fine, font_style)
        ws.write(row_num, 6, transaction.others, font_style)
        ws.write(row_num, 7, transaction.total_amount_paid, font_style)
        ws.write(row_num, 8, transaction.remaining_loan_amount, font_style)
        ws.write(row_num, 9, transaction.additional_loan_amount, font_style)
        ws.write(row_num, 10, transaction.total_loan_amount, font_style)

    wb.save(response)
    return response
Exemplo n.º 21
0
for f in files:
    print("reading from ", f)
    with open(f, 'r') as fp:
        for line in fp:
            data = json.loads(line)
            try:
                date_nep = data["date_nepali"].split(",")[1:3]
                # print(nd)
                yy = "".join([str(digit(c)) for c in date_nep[1][1:]])
                if int(yy) < 2076:
                    print("filtered out article from year ", yy)
                    continue
                dd = "".join(
                    [str(digit(c)) for c in date_nep[0].strip().split(' ')[1]])
                mm = month_map[date_nep[0].strip().split(' ')[0]]
                nd = NepaliDate(yy, mm, dd, lang='nep')
                # print(yy, mm, dd, nd, , )
                d_eng = nd.to_english_date()
                month = d_eng.month
                id_ = data["id"]
                if month not in {8, 9, 10}:
                    print("filtered out article ", data["url"])
                    continue
                if id_ in ids:
                    print("duplicate ")
                    continue
                data["date_english"] = d_eng.strftime("%Y/%-m/%d")
                data["title"] = data["title"].replace(u'\xa0', u' ')
                data["subtitle"] = data["subtitle"].replace(u'\xa0', u' ')
                data["description"] = data["description"].replace(
                    u'\xa0', u' ')
Exemplo n.º 22
0
def convert_to_english(date):
    year, month, day = [int(s) for s in date.split("-") if s.isdigit()]
    nepali_date = NepaliDate(year, month, day)
    en_date = nepali_date.to_english_date()
    return en_date