Ejemplo n.º 1
0
 def __str__(self):
     jdatetime.set_locale(locale='fa_IR')
     date = jdatetime.date.fromgregorian(
         day=self.date.day,
         month=self.date.month,
         year=self.date.year
     )
     return date.strftime('%d %B %y')
Ejemplo n.º 2
0
def mergeIranbourseAllNamadExcelsByNamadd(InputDir="NamadsExcelsFromIranBourse", OutputFile="AllDataByNamads.pkl"):
    jdatetime.set_locale('fa_IR')

    allData = {}

    for root, dirs, files in os.walk(InputDir):
        files.sort()
        print('start readin files')
        fi = 0.0
        for filename in files:
            print(str(int(fi / files.__len__() * 100.0)) + ' %  ... ' + filename)
            fi += 1.0
            try:
                df_list = pandas.read_html(InputDir + '/' + filename)
            except ValueError as e:
                if e.args[0] == 'No tables found':
                    continue
                else:
                    raise e

            if len(df_list) < 1:
                print('no Data Frame in > ' + filename)
                continue

            df = df_list[0]  # first frame only !
            # df.to_csv('DataPreparing/Data/table {}.csv'.format(0))
            if df.isnull().values.any():
                print('null value in > ' + filename)
                continue

            parts = filename.split('.')[0].split('_')
            NamadId = parts[1]
            NamadCode = parts[2]

            thisNamad = {}
            for col in df.columns.values:
                idx = 0
                for v in df[col].values:
                    if idx not in thisNamad:
                        thisNamad[idx] = {}
                    if col == str('تاريخ'):
                        date = v.split('/')
                        pd = jdatetime.date(int(date[0]), int(date[1]), int(date[2]))
                        thisNamad[idx][col] = pd
                    else:
                        if type(v) == numpy.int64:
                            thisNamad[idx][col] = int(v)
                        else:
                            thisNamad[idx][col] = v
                    idx += 1

            allData[NamadId] = thisNamad

    f = open(OutputFile, "wb")
    pickle.dump(allData, f)
    f.close()
Ejemplo n.º 3
0
def showTable(request):
    if not request.user.is_superuser:
        return redirect('/admin')
    users = models.Person.objects.order_by('id')
    jdatetime.set_locale("fa_IR")
    context = {
        'users': users,
        'date': jdatetime.datetime.now().strftime('%Y/%-m/%-d')
    }
    return render(request, 'eaecontrol/index.html', context)
Ejemplo n.º 4
0
 def record_thread_locale(record, event, locale):
     """Set and capture locale in current thread.
     Use an event to coordinate execution for multithreaded
     tests. Because thread idents maybe recycled and reused
     and jdatetime uses threads idents to identify unique
     threads.
     """
     event.wait(timeout=10)
     jdatetime.set_locale(locale)
     record.append(jdatetime.get_locale())
Ejemplo n.º 5
0
 def record_thread_locale(record, event, locale):
     """Set and capture locale in current thread.
     Use an event to coordinate execution for multithreaded
     tests. Because thread idents maybe recycled and reused
     and jdatetime uses threads idents to identify unique
     threads.
     """
     event.wait(timeout=10)
     jdatetime.set_locale(locale)
     record.append(jdatetime.get_locale())
Ejemplo n.º 6
0
def add():
    jdatetime.set_locale('fa_IR')
    if not current_user.is_authenticated:
        return redirect(url_for('.login'))
    print(jdatetime.datetime.now().strftime("%a, %d %b %Y %H:%M:%S"))
    regby = current_user.surename
    if request.method == "POST":

        #print(request.form.getlist("accessories"))
        accs = (listtostrint(request.form.getlist("accessories")))
        #temp=request.form["customer_phone"]
        tracking_number = random.randint(1000000, 9999999)
        customer_name = request.form["customer_name"]
        customer_phone = request.form["customer_phone"]
        device_type = request.form["device_type"]
        device_model = request.form["device_model"]
        serial_number = request.form["serial_number"]
        property_number = request.form["property_number"]
        address = request.form["address"]
        problem = request.form["problem"]
        accesories = accs
        other_text = request.form["other_text"]
        giver_name = request.form["giver_name"]
        situation = 0
        deliverd = 0
        in_time = jdatetime.datetime.now().strftime("%a, %d %b %Y %H:%M:%S")

        #in_time=request.form["in_time"]
        # out_time=request.form["out_time"]
        newone = devices(tracking_number=tracking_number,
                         customer_name=customer_name,
                         customer_phone=customer_phone,
                         device_type=device_type,
                         device_model=device_model,
                         serial_number=serial_number,
                         property_number=property_number,
                         address=address,
                         problem=problem,
                         other_text=other_text,
                         giver_name=giver_name,
                         in_time=in_time,
                         out_time='',
                         situation=situation,
                         deliverd=deliverd,
                         accesories=accesories)
        db.session.add(newone)
        db.session.commit()
        return redirect('/')
    else:
        pass
    return render_template(
        'add.html',
        time=jdatetime.datetime.now().strftime("%a, %d %b %Y %H:%M:%S"),
        regby=regby)
Ejemplo n.º 7
0
 def __str__(self):
     jdatetime.set_locale("fa_IR")
     date = jdatetime.datetime.fromgregorian(second=self.date_time.second,
                                             minute=self.date_time.minute,
                                             hour=self.date_time.hour,
                                             day=self.date_time.day,
                                             month=self.date_time.month,
                                             year=self.date_time.year)
     output = self.user.get_full_name() + " - " + f2p(
         date.strftime("%d %B %y"))
     return output
Ejemplo n.º 8
0
 def jd_create_datetime(self):
     jdatetime.set_locale('fa_IR')
     jdatetime.datetime.now().strftime('%A %B')
     jd_datetime = jdatetime.datetime.fromgregorian(
          year = self.create_datetime.year(),
          month = self.create_datetime.month(),
          hour = self.create_datetime.hour(),
          minute = self.create_datetime.minute(),
          second = self.create_datetime.second()
         )
     return dj_datetime.strftime("%A, %d %B %y %H:%M:%S")
Ejemplo n.º 9
0
 def jd_create_datetime(self):
     jdatetime.set_locale('fa_IR')
     jdatetime.datetime.now().strftime('%A %B')
     jd_datetime = jdatetime.datetime.fromgregorian(
         year=self.create_datetime.year,
         month=self.create_datetime.month,
         day=self.create_datetime.day,
         hour=self.create_datetime.hour,
         monute=self.create_datetime.minute,
         second=self.create_datetime.second,
     )
     return jd_datetime.strftime('%A, %d %B %y %H:%M:%S')
Ejemplo n.º 10
0
def mergeIranbourseAllDayExcelsByDays(InputDir="DailyExcelsFromIranBourse", OutputFile="AllDataByDays.pkl"):
    jdatetime.set_locale('fa_IR')

    allData = {}
    # if not os.path.exists(InputDir):
    #     os.makedirs(InputDir)

    for root, dirs, files in os.walk(InputDir):
        files.sort()
        print('start readin files')
        fi = 0.0
        for filename in files:
            print(str(int(fi / files.__len__() * 100.0)) + ' %  ... ' + filename)
            fi += 1.0
            try:
                df_list = pandas.read_html(InputDir + '/' + filename)
            except ValueError as e:
                if e.args[0] == 'No tables found':
                    continue
                else:
                    raise e

            if len(df_list) < 1:
                print('no Data Frame in > ' + filename)
                continue

            df = df_list[0]  # first frame only !
            # df.to_csv('DataPreparing/Data/table {}.csv'.format(0))
            if df.isnull().values.any():
                print('null value in > ' + filename)
                continue

            date = filename.split('.')[0].split('_')
            pd = jdatetime.date(int(date[1]), int(date[2]), int(date[3]))
            ed = pd.togregorian()
            dayInWeek = ed.strftime("%A")
            pdayInWeek = pd.strftime("%A")

            thisday = {}
            for col in df.columns.values:
                # thisday[col] = df[col].values
                idx = 0
                for v in df[col].values:
                    if idx not in thisday:
                        thisday[idx] = {}
                    thisday[idx][col] = v
                    idx += 1

            allData[pd] = thisday

    f = open(OutputFile, "wb")
    pickle.dump(allData, f)
    f.close()
Ejemplo n.º 11
0
def get_last_months(
        count: int = 1,
        today: Optional[date] = None) -> Generator[JalaliMonth, None, None]:

    if not today:
        today = date.today()

    jdatetime.set_locale("fa_IR")
    today_jalali = jdatetime.date.fromgregorian(date=today)

    # Year will decrease if month<0
    year = today_jalali.year
    # Month will decrease in every loop
    month = today_jalali.month + 1

    # for each last month
    for _ in range(count):

        # Decrease 1 month, If result is negative
        # decrease year and normalize month
        month -= 1
        if month <= 0:
            year -= 1
            month = normalize_month(month)

        start_date = jdatetime.datetime(year, month, 1)

        # end_date_month is 1 month after start. If result is more than 12,
        # set end_date_year to 1 year after start year and normalize month,
        # otherwise set  to start date year.
        end_date_month = month + 1
        if month >= 12:
            end_date_month = normalize_month(end_date_month)
            end_date_year = year + 1
        else:
            end_date_year = year

        end_date = jdatetime.datetime(end_date_year, end_date_month, 1)

        yield JalaliMonth(
            start_date.togregorian(),
            end_date.togregorian(),
            start_date.strftime("%b %Y"),
        )
Ejemplo n.º 12
0
    def index(request):
        if request.user.is_authenticated:
            jdatetime.set_locale('fa_IR')
            # print(jdatetime.datetime.now().hour)
            # print(jdatetime.datetime.now().minute)
            # print(datetime.datetime.now().hour)
            # print(datetime.datetime.now().minute)
            return render(request, 'integration/index.html', {
                'user': {'name': 'user1'},
                'local_time_hour': jdatetime.datetime.now().hour,
                'local_time_minute': jdatetime.datetime.now().minute,

                'local_date_year': jdatetime.datetime.now().year,
                'local_date_month': month_name(jdatetime.datetime.now().month),
                'local_date_day': jdatetime.datetime.now().day,
                'local_date_weekday': weekday_name(jdatetime.datetime.now().weekday()),
            })
        else:
            return redirect(reverse("user.login"))
Ejemplo n.º 13
0
def showTable(request):
    if not request.user.has_perm('eaecontrol.view_person'):
        return redirect('/admin')
    users = models.Person.objects.order_by('id')
    for user in users:
        recs = models.Timing.objects.filter(
            person=user, date=datetime.datetime.now().date())
        if recs.exists():
            user.lastStatusChangeTime = recs.last().time
            user.save()
        else:
            user.lastStatusChangeTime = None
            user.save()
    jdatetime.set_locale("fa_IR")
    context = {
        'users': users,
        'date': jdatetime.datetime.now().strftime('%Y/%-m/%-d'),
        'ver': '1.1.0'
    }
    return render(request, 'eaecontrol/index.html', context)
Ejemplo n.º 14
0
 def date_time():
     dt = t.Turtle()
     tm = t.Turtle()
     dt.speed(0)
     tm.speed(0)
     jdatetime.set_locale('fa_IR')
     tm.pu()
     tm.goto(-240, 215)
     tm.pd()
     dt.pu()
     dt.goto(267, 215)
     dt.pd()
     dt.ht()
     tm.ht()
     dt.ht()
     tm.ht()
     dt.fd(1)
     tm.fd(1)
     while True:
         file = open("data/dtcheck.txt", "r")
         dtval = file.read()
         file.close()
         if (dtval == "1"):
             now = datetime.now()
             now_date = jdatetime.datetime.now().strftime(
                 "%Y/%m/%d")
             now_time = jdatetime.datetime.now().strftime(
                 "%H:%M")
             dt.undo()
             tm.undo()
             dt.pencolor("black")
             tm.pencolor("black")
             dt.write(now_time,
                      align="center",
                      font=("B Titr", 15))
             tm.write(now_date,
                      align="center",
                      font=("B Titr", 15))
             time.sleep(1)
Ejemplo n.º 15
0
 def record_locale_formatted_date(record, locale):
     jdatetime.set_locale(locale)
     dt = jdatetime.date(1397, 3, 27)
     record.append(dt.strftime('%A'))
     record.append(dt.strftime('%B'))
Ejemplo n.º 16
0
 def record_greenlet_locale_nl():
     jdatetime.set_locale('nl_NL')
     fa_greenlet.switch()
     nl_record.append(jdatetime.get_locale())
     fa_greenlet.switch()
Ejemplo n.º 17
0
 def record_greenlet_locale_fa():
     jdatetime.set_locale('fa_IR')
     nl_greenlet.switch()
     fa_record.append(jdatetime.get_locale())
     nl_greenlet.switch()
Ejemplo n.º 18
0
 def date_text(self):
     jdatetime.set_locale('Persian_Iran')
     return jalali_date(self.date).strftime('%A، %-d %B %Y')
Ejemplo n.º 19
0
 def test_init_locale_is_effective_only_if_not_empty(self):
     orig_locale = jdatetime.get_locale()
     jdatetime.set_locale('nl_NL')
     self.addCleanup(jdatetime.set_locale, orig_locale)
     date = jdatetime.date(1397, 4, 22, locale='')
     self.assertEqual(date.locale, 'nl_NL')
Ejemplo n.º 20
0
 def test_init_locale_is_effective_only_if_not_none(self):
     orig_locale = jdatetime.get_locale()
     jdatetime.set_locale('en_US')
     self.addCleanup(jdatetime.set_locale, orig_locale)
     date = jdatetime.date(1397, 4, 22, locale=None)
     self.assertEqual(date.locale, 'en_US')
Ejemplo n.º 21
0
 def test_init_locale_is_effective_only_if_not_none(self):
     orig_locale = jdatetime.get_locale()
     jdatetime.set_locale('en_US')
     self.addCleanup(jdatetime.set_locale, orig_locale)
     date = jdatetime.date(1397, 4, 22, locale=None)
     self.assertEqual(date.locale, 'en_US')
Ejemplo n.º 22
0
from flask_sqlalchemy  import SQLAlchemy
from flask_login import LoginManager,UserMixin,login_user,login_required,logout_user,current_user
import secrets
import jdatetime
from werkzeug.utils import secure_filename


app = Flask(__name__)
secret = secrets.token_urlsafe(32)
app.secret_key = secret
app.config['SQLALCHEMY_DATABASE_URI']='sqlite:///blog.sqlite3'
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"]=False
db = SQLAlchemy(app)
Login_manager= LoginManager()
Login_manager.init_app(app)
jdatetime.set_locale('fa_IR')



class posts(db.Model):

    id= db.Column("id", db.Integer , primary_key=True)
    tittle=db.Column(db.String(200))
    content=db.Column(db.Text)
    writer=db.Column(db.String(100))
    date=db.Column(db.String(100))
    img=db.Column(db.Text)
    imgname=db.Column(db.Text)
    mimetype=db.Column(db.Text)

class users(UserMixin,db.Model):
Ejemplo n.º 23
0
 def record_locale_formatted_date(record, locale):
     jdatetime.set_locale(locale)
     dt = jdatetime.date(1397, 3, 27)
     record.append(dt.strftime('%A'))
     record.append(dt.strftime('%B'))
Ejemplo n.º 24
0
 def record_greenlet_locale_nl():
     jdatetime.set_locale('nl_NL')
     fa_greenlet.switch()
     nl_record.append(jdatetime.get_locale())
     fa_greenlet.switch()
Ejemplo n.º 25
0
def mergeIranbourseAllDayExcelsByNamads(InputDir="DailyExcelsFromIranBourse", OutputFile="AllDataByNamad.pkl"):
    jdatetime.set_locale('fa_IR')

    allData = {}
    # if not os.path.exists(InputDir):
    #     os.makedirs(InputDir)

    for root, dirs, files in os.walk(InputDir):
        files.sort()
        print('start readin files')
        fi = 0.0
        for filename in files:
            print(str(int(fi / files.__len__() * 100.0)) + ' %  ... ' + filename)
            fi += 1.0
            df_list = pandas.read_html(InputDir + '/' + filename)

            if len(df_list) < 1:
                print('no Data Frame in > ' + filename)
                continue

            df = df_list[0]  # first frame only !
            # df.to_csv('DataPreparing/Data/table {}.csv'.format(0))
            if df.isnull().values.any():
                print('null value in > ' + filename)
                continue

            date = filename.split('.')[0].split('_')
            pd = jdatetime.date(int(date[1]), int(date[2]), int(date[3]))
            ed = pd.togregorian()
            dayInWeek = ed.strftime("%A")
            pdayInWeek = pd.strftime("%A")

            namadha = df['نماد'].values
            for sotoon in df.dtypes.index.values:
                # if t == 'نام' or t == 'نماد' :
                if sotoon == 'نماد':
                    continue
                # n =df[t].values
                i = 0
                for meqdar in df[sotoon].values:
                    if namadha[i] not in allData:
                        allData[namadha[i]] = {}

                    if sotoon == 'نام':
                        allData[namadha[i]][sotoon] = meqdar
                        continue
                    if sotoon not in allData[namadha[i]]:
                        allData[namadha[i]][sotoon] = []

                    allData[namadha[i]][sotoon].append(
                        {'v': meqdar, 'pd': pd, 'eInWeek': dayInWeek, 'pInWeek': pdayInWeek})
                    i += 1

            # print(pd)

    for namad in allData:
        for sotoon in allData[namad]:
            if sotoon == 'نام':
                continue
            allData[namad][sotoon].sort(key=lambda k: k['pd'])

    f = open(OutputFile, "wb")
    pickle.dump(allData, f)
    f.close()
Ejemplo n.º 26
0
def update():
    jdatetime.set_locale('fa_IR')
    date = jdatetime.datetime.now().strftime("%a, %d %b %Y")
    time = jdatetime.datetime.now().strftime("%H:%M:%S")
    return jsonify({'time': time, 'date': date})
Ejemplo n.º 27
0
def to_jdatetime(dtime):
    jdatetime.set_locale("fa_IR")
    dtime = dtime + timedelta(hours=9, minutes=30)
    return jdatetime.datetime.fromgregorian(
        datetime=dtime).strftime("%a, %d %b %Y %H:%M:%S")
Ejemplo n.º 28
0
 def test_init_locale_is_effective_only_if_not_empty(self):
     orig_locale = jdatetime.get_locale()
     jdatetime.set_locale('nl_NL')
     self.addCleanup(jdatetime.set_locale, orig_locale)
     date = jdatetime.date(1397, 4, 22, locale='')
     self.assertEqual(date.locale, 'nl_NL')
Ejemplo n.º 29
0
def index(request):
    jdatetime.set_locale('fa_IR')
    boardgames = Boardgame.objects.all()
    counts = boardgames.count()
    events = Event.objects.all()
    events_list = []
    dorna_events = EventDorna.objects.all()
    dorna_events_list = []
    for event in events:
        jalali_date = jdatetime.date.fromgregorian(date=event.datetime.date())
        name_day = jalali_date.strftime("%a")
        month_name = jalali_date.strftime("%b")
        events_list.append({
            "date": {
                "day": name_day,
                "month_name": month_name,
                "jalali": jalali_date,
                "image": event.image.url
            },
            "event": event
        })

    for event in dorna_events:
        jalali_date = jdatetime.date.fromgregorian(date=event.datetime.date())
        name_day = jalali_date.strftime("%a")
        month_name = jalali_date.strftime("%b")
        dorna_events_list.append({
            "date": {
                "day": name_day,
                "month_name": month_name,
                "jalali": jalali_date,
                "image": event.image.url
            },
            "event": event
        })

    leads_dict = []
    all_leads = LeaderBoard.objects.all()
    for lead in all_leads:
        ranks = PersonToLeaderBoard.objects.filter(
            leader_board=lead).order_by("rank")
        rank_data = []
        for rank in ranks:
            rank_data.append({
                "name": rank.person_name,
                "points": rank.points,
                "rank": rank.rank
            })
        lead_data = {
            "boardgame": lead.boardgame_name,
            "robot_number": lead.robot_number,
            "ranks": rank_data
        }
        leads_dict.append(lead_data)

    print(leads_dict)
    return render(
        request, 'index.html', {
            'boardgames_count': counts,
            "events": events_list,
            "dorna_events": dorna_events_list,
            "tabletop_games": get_tabletop_games(),
            "lead_data": leads_dict
        })
Ejemplo n.º 30
0
 def record_greenlet_locale_fa():
     jdatetime.set_locale('fa_IR')
     nl_greenlet.switch()
     fa_record.append(jdatetime.get_locale())
     nl_greenlet.switch()