شما هنوز به سیستم وارد نشده اید.
خیلی میتونه کاربردی باشه. اما استفاده از caseهای مشابه درحالیکه 3$ و 4$ بجای regular expressionهای 3$.* و 4$.* جایگزین شده باشن احتمالا نتایج شبیهی به دو حالت دیگه که مدّ نظرتون هست خواهد داد (cat filename | grep ...).
ویرایش: یک ایده شیک تر میتونه استفاده از روشی باشه که احسان در اینجا برای کنترل کردن تمام پسوندها انجام داده؛ یعنی ساختن آرایه ای از پسوندها (بهرحال، حتی در غیر اینصورت، ایده استفاده از xargs مفیدتر به نظر میرسه).
آخرین ویرایش توسط Arcush (2016-10-13 14:28:55)
آفلاین
آیا از دسکتاپ ثابت خود خسته شده اید؟ خب دیگر خسته نشوید لطفا
یه اسکریپت باحال که دل و جگرش به فضاپیمای آب و هوا شناسی Himawari 8 وصله و توی هر ۱۰ دقیقه به صورت زنده عکسی از زمین روی دسکتاپتون ست میکنه.
و البته که این اسکریپت مال من نیست
آفلاین
میزکار kde-plasma رو تازگی نصب کردم و خیلی تحت تاثیر قرار گرفتم اما وقتی مساله به استفاده از دو مونیتور می رسه kde اصلا روی خوش نشون نمیده پنل متوقف می شد و گاهی هم کل دسکتاپ کرش می کرد. بعد یه مدت امتحان روش های مختلف به روش زیر رسیدم که امیدوارم اگر این مشکل رو دارید با kde براتون مفید باشه:
#!/bin/bash
xrandr --output currentMonitor --primary
xrandr --output secondMonitor --right-of currentMonitor
killall plasmashel
/bin/plasmashell & disown
ابتدا مانیتور فعلی رو به عنوان پیشفرض ست میکنه بعد دومی رو میذاره سمت راس اولی و بعد پلاسما رو میبنده و سپس دوباره استارتش میکنه.
برای لپ تاپ هایی که رزولوشن صفحه بعد بوت به درستی ست نمیشه (به دلایل مختلف) هم این روش جواب میده:
ابتدا یه اسکریپت برای رزولوشن میسازید که هربار تو بوت باید استارتش کنید:
/bin/kde_resolution.sh
#!/bin/bash
xrandr --newmode "3840x2160_60.00" 712.75 3840 4160 4576 5312 2160 2163 2168 2237 -hsync +vsync
xrandr --addmode monitorName 3840x2160_60.00
xrandr --output monitorName --mode 3840x2160_60.00
توجه کنید که دستور اول رو باید با استفاده از این صفحه بدست بیارید.
و برای استفاده از دو مونیتور میتونید از این استفاده کنید:
#!/bin/bash
xrandr --output currentMonitor --primary
/bin/kde_resolution.sh
xrandr --output secondMonitor --right-of currentMonitor
killall plasmashel
/bin/plasmashell & disown
آخرین ویرایش توسط mazhar (2016-11-17 13:14:53)
آفلاین
مظهر جان یه سوال خارج از بحث.
kde رو من تا حالا نصب نکردم.چون هر سری میخواستم نصب کنم دوستای kde دارمون میگفتن که هنوز ناپایداره و باگ های بد عنقی داره!
آیا هم چنان این روال درسته یا نه میشه به عنوان کار روزمره ازش استفاده کرد؟
آفلاین
سلام و عرض ادب
راستش یه بار نصب کرده بودم و ازش اصلا راضی نبودم چون واقعا جوابگو نبود (سیستم ضعیفی داشتم). ولی دقیقاً دو هفته پیش آوردم رو لپ تاپم تست کنم و به طرز غیر قابل قبولی شگفت زده شدم! فقط نصب کنید و لذت ببرید همین امروز هم که از dual display باگ داشت و حل شد. به غیر از این مورد تا حالا هیچ موردی نداشتم باهاش
آفلاین
سپاس از راهنمایی تون مظهر عزیز
آفلاین
مخلصیم
آفلاین
با توجه به اینکه بسیاری از برنامه هایی که کار های حرفه ای انجام میدن مقدار بسیار زیاد Ram رو به خودشون اختصاص میدن گاهی مواقع ممکنه باعث کرش شدن سیستم بشن، مثلا همین کد cpp:
#include <iostream>
using namespace std;
int main()
{
int n = 20;
char *pch;
while (1)
{
pch = new char[n];
}
return 0;
}
که اگر در یک سیستم لینوکسی کامپایل و اجرا شود، رم را پر کرده و باعث هنگ کردن سیستم می شود.
راه حلی که پیدا کردم timeout بود:
این اسکریپت به perl 5 نیاز دارد. برای استفاده به عنوان محدود کننده ی رم، اسکریپت را اینگونه فراخوانی کنید:
./timeout -m <ram_amount> <command>
که amount_ram حد اکثر مقدار رمی است که به این command اختصاص داده می شود. در ضمن command می تواند هر برنامه یا حتی دستور شل باشد.
آخرین ویرایش توسط mazhar (2016-12-31 10:36:31)
آفلاین
سلام، من اخیرا برای پشتیبانی توی يه ISP رزومه فرستاده بودم، یکی از اولین شرایطش این بود که سوالات بخش "سوالات متداول" شون رو بخونیم و بلد باشیم، اکثر هم گروهیام ویندوزی بودند و با دیدن این که این کار چه قدر میتونه زمانبر باشه، قید این سوالا رو زدن، (برای دیدن هر سوال بایستی یه page جدید باز شه و ادامهی کار) من که قبلا یکم تجربه وب اسکرپینگ با پایتون رو داشتم، به سرم زد که یه کار باحال بکنم، حدود دو ساعت وقتمو گرفت، ولی حسی که بعدش داشتم کاملا وقتمو جبران کرد:
#!/usr/bin/env python3.5
# Author: Ehsan Faalpoor <faalpoor.ehsan@gmail.com>
import requests
import bs4
import os
URL = "http://www.asiatech.ir/"
def getTopLayerPage(main_url):
modifiedURL = main_url + '/faq'
page = requests.get(main_url + '/faq')
soup = bs4.BeautifulSoup(page.text, "html.parser")
Table = soup.find('table', {'style': 'width: 100%;', 'cellspacing': '1', 'cellpadding': '5' ,'border': '0', 'align': 'center'})
for Header in Table.findAll('a', {'href': True}):
yield '{}{}'.format(URL, Header['href']) , Header.string
def howManyPages(HeaderURl):
page = requests.get(HeaderURl)
soup =bs4.BeautifulSoup(page.text, 'html.parser')
subPages = soup.find('div', {'class': 'pagination'})
if not subPages.find('a'):
yield '{}'.format(HeaderURl)
else:
for subPage in subPages.findAll('a', {'href': True}):
yield '{}{}'.format(URL, subPage['href'])
yield '{}'.format(HeaderURl)
def crawlTheCategory(listOfPage,Title):
currentPath = os.getcwd()
with open(currentPath + '/{}.Question'.format(Title), 'w') as fd:
fd.write(Title + '\n')
QuestionCounter = 1
for pageNumber in listOfPage:
page = requests.get(pageNumber)
soup = bs4.BeautifulSoup(page.text, 'html.parser')
for QuestionDiv in soup.findAll('h3', {'class': 'mypets1'}):
QuestionLink = URL + QuestionDiv.find('a')['href']
QuestionPage = requests.get(QuestionLink)
Qsoup = bs4.BeautifulSoup(QuestionPage.text, 'html.parser')
fd.write(str(QuestionCounter) + '- ' + Qsoup.find('h1', {'class': 'titlepage'}).string + '\n')
Context = Qsoup.find('div', {'class': 'col-md-12 col-sm-12 col-xs-12'}).find('p').text
fd.write(Context + '\n')
fd.write('\n')
QuestionCounter += 1
def main():
for pageURL, Title in getTopLayerPage(URL):
subPage = {sb for sb in howManyPages(pageURL)}
crawlTheCategory(sorted(subPage), Title)
if __name__ == '__main__':
main()
الان بسته به تعداد دسته بندی هایی که برای سوالاشون دارن ما یه سری تکست داریم، که از اینجا به بعد میدیمش به لیبرهآفیس.
(بعضی از دسته بندی ها بیشتر از یه صفحه سوال داشتند و تقریبا دو یا سه تا از سوالات هم مثله بقیه از تگ p برای متن استفاده نکرده بودن که اونا رو ناچارا دستی درست کردم)
این هم فایل نهایی.
آخرین ویرایش توسط ehsan_faal (2017-01-09 11:17:15)
Mahatma Gandhi - The weak can never forgive. Forgiveness is the attribute of the strong
آفلاین
یه اسکریپت واسه تنبل ها:( من جمله خودم)
من اهل فیلمم، کتاب الکترونیکی هم زیاد میخونم، دوست دارم همشون همیشه دم دست باشن، بهترین راه حل واسه من درست کردن لینک به اون فایلهاست.
اما خب یکم دردسر داره که شما باید مسیر کامل فایل رو واسه درست کردن لینک رو بدی همیشه، فایلتون رو به این اسکریپت پاس میدید، توی دسکتاپتون یه فلدر به اسم شرتکات میسازه و اون فایل رو لینک میکنه به اونجا، هر سری هم چک میکنه که اگه لینک مرده ای اونجا باشه حذفش کنه.
#!/usr/bin/env python3
import os
import sys
import getpass
from subprocess import call
def main():
realpath = os.path.abspath(sys.argv[1])
user = getpass.getuser()
destination = '/home/{}/Desktop/shortcuts/'.format(user)
if not os.path.exists(destination):
os.mkdir(destination)
call(['find', destination, '-xtype', 'l', '-delete'])
target = '{}{}'.format(destination, sys.argv[1])
if not os.path.exists(target):
returnCode = call(['ln', '-s', realpath, target])
if returnCode == 0:
print('The Operation was successful.')
else:
print("There's something wrong during operation. Error Code: {}".format(returnCode))
else:
sys.exit("There's a file with the same name as input in the destination folder. Making soft link is skipped.")
if __name__ == '__main__':
if len(sys.argv) == 2:
main()
آخرین ویرایش توسط ehsan_faal (2017-01-22 15:03:16)
Mahatma Gandhi - The weak can never forgive. Forgiveness is the attribute of the strong
آفلاین
بدست آوردن اطلاعاتی راجع به لینک دانلود( مشابه کاری که اسپایدر میکنه)
شما میتونین به این اسکریپت یه لینک دانلود یا یه فایل حاوی لینکهای دانلود پاس بدید تا بهتون سایز هر لینک و نوع دیتا و نامش رو بده.
اسپایدر wget هم همینکارو میکنه منتها من نیاز داشتم یکم اطلاعات مختصرتر و ترتمیز تری داشته باشم.
#!/usr/bin/env python3.6
import os
import sys
import requests
import prettytable
def smartSize(nOctet):
if nOctet is None:
return None
else:
nOctet = int(nOctet)
nKiB = nOctet / 1024
if nKiB <= 1023:
return nKiB, 'KiB'
else:
nMiB = nKiB / 1024
if nMiB <= 1023:
return nMiB, 'MiB'
else:
nGiB = nMiB / 1024
return nGiB, 'GiB'
def inputIsFile():
with open(sys.argv[1], 'r') as links:
tabularData = prettytable.PrettyTable(
['File Name', 'File Type', 'File Size'])
for link in links:
response = requests.head(link.rstrip())
if response.reason != 'OK':
continue
name = requests.utils.unquote(link).split('/')[-1]
size = smartSize(response.headers.get('Content-Length', None))
fileType = response.headers.get('Content-Type', None)
if size is not None or fileType.startswith('text/html'):
tabularData.add_row(
[name, fileType, '{:.3f} {}'.format(size[0], size[1])])
else:
if fileType.startswith('text/html'):
continue
tabularData.add_row([name, fileType, size])
print(tabularData)
def singleURL():
response = requests.head(sys.argv[1])
if response.reason != 'OK':
sys.exit('There\'s something wrong with your URL, Got {}'.format(
response.status_code))
name = requests.utils.unquote(sys.argv[1]).split('/')[-1]
size = smartSize(response.headers.get('Content-Length', None))
filetype = response.headers.get('Content-Type', None)
if size is not None:
print('\nFile Name: {}\nFile Type: {}\nFile Size: {:.3f} {}'.format(
name, filetype, size[0], size[1]))
else:
if filetype.startswith('text/html'):
sys.exit('The remote File doesn\'t exist.')
print('\nFile Name: {}\nFile Type: {}\nFile Size: {}'.format(
name, filetype, size))
def main():
if os.path.isfile(sys.argv[1]):
inputIsFile()
else:
singleURL()
if __name__ == '__main__':
if len(sys.argv) != 2:
sys.exit('''1 argument is needed, you passed {}.
You should pass this script a downloadable link or a file consist of downloadable links.'''.format(len(sys.argv) - 1))
else:
main()
نتیجه ی اجرا روی یه فایل حاوی لینکهای دانلود سریال BBT:
+----------------------------------------------------------+--------------------------+-------------+
| File Name | File Type | File Size |
+----------------------------------------------------------+--------------------------+-------------+
| The Big Bang Theory S10E01 1080p HDTV x265_AVADL.BiZ.mkv | application/octet-stream | 320.708 MiB |
| | | |
| The Big Bang Theory S10E02 1080p HDTV x265_AVADL.BiZ.mkv | application/octet-stream | 266.059 MiB |
| | | |
| The Big Bang Theory S10E03 1080p HDTV x265_AVADL.BiZ.mkv | application/octet-stream | 235.355 MiB |
| | | |
| The Big Bang Theory S10E04 1080p HDTV x265_AVADL.BiZ.mkv | application/octet-stream | 256.318 MiB |
| | | |
| The Big Bang Theory S10E05 1080p HDTV x265_AVADL.BiZ.mkv | application/octet-stream | 229.315 MiB |
| | | |
| The Big Bang Theory S10E06 1080p HDTV x265_AVADL.BiZ.mkv | application/octet-stream | 303.587 MiB |
| | | |
| The Big Bang Theory S10E07 1080p HDTV x265_AVADL.BiZ.mkv | application/octet-stream | 309.226 MiB |
| | | |
| The Big Bang Theory S10E08 1080p HDTV x265_AVADL.BiZ.mkv | application/octet-stream | 247.850 MiB |
| | | |
| The Big Bang Theory S10E09 1080p HDTV x265_AVADL.BiZ.mkv | application/octet-stream | 270.729 MiB |
| | | |
| The Big Bang Theory S10E10 1080p HDTV x265_AVADL.BiZ.mkv | application/octet-stream | 385.516 MiB |
| | | |
| The Big Bang Theory S10E11 1080p HDTV x265_AVADL.BiZ.mkv | application/octet-stream | 302.050 MiB |
| | | |
+----------------------------------------------------------+--------------------------+-------------+
آخرین ویرایش توسط ehsan_faal (2017-02-05 17:20:29)
Mahatma Gandhi - The weak can never forgive. Forgiveness is the attribute of the strong
آفلاین
با سلام یه اسکریپت برای خارج کردن فایل ها از حالت فشرده نوشتم به دلیل اینکه خیلی دیگه مرسوم شده فایل های سایت ها به صورت فشرده باشند و به همراه پسوورد
این اسکریپت سه فرمت فایل zip , 7z ,rar را از حالت فشرده خارج می کنه که فایل هایی که فرمت rar دارند را در دوحالت فایل بدون پسوورد و با پسوورد در نظر گرفتم, همچنین پس از اتمام کار extract کردن هر فایل آن را پاک می کنه
بسته های پیش نیاز هم شامل :
p7zip , unrar , unzip
#!/bin/bash
IFS=$'\n'
ls -1 *.rar > /tmp/lsrar.txt
ls -1 *.zip > /tmp/lszip.txt
ls -1 *.7z* > /tmp/ls7z.txt
clear
##
rarpass(){
name=$1
while read line; do
name=$line
unrar x -o+ -p$pass $name
rm $name
done < /tmp/lsrar.txt
}
##
rar () {
name=$1
while read line; do
name=$line
unrar x -o+ $name
rm $name
done < /tmp/lsrar.txt
}
###
rarfile (){
read -p "have files password?(y/n): " ans
if [ $ans == "y" ] ;then
read -p "enter the password: " pass
rarpass
elif [ $ans == "n" ];then
rar
else
exit
fi
}
###
7zfile (){
name=$1
while read line; do
name=$line
7za x $name && rm $name
done < /tmp/ls7z.txt
}
##
zipfile (){
name=$1
while read line; do
name=$line
unzip $name
rm $name
done < /tmp/lszip.txt
}
##
tmpclean (){
rm /tmp/ls*.txt
}
read -p "choose your file formant enter like this (7z or zip or rar): " format
if [ $format == "rar" ] ;then
rarfile
tmpclean
elif [ $format == "zip" ];then
zipfile
tmpclean
elif [ $format == "7z" ];then
7zfile
tmpclean
else
tmpclean
exit
fi
Friends help friends use Gnu/Linux
آفلاین
بسته ی unp رو نصب کنید
آخرین ویرایش توسط ehsan_faal (2017-02-06 15:14:35)
Mahatma Gandhi - The weak can never forgive. Forgiveness is the attribute of the strong
آفلاین
اسکریپت زیر واسه خودم که خیلی خیلی کاربردیه، tile کردن پنجرهها خیلی وقتا جوابگوی نیاز من نیست و روی xubuntu هم چیزی مثله gTile پیدا نکردم، اینو نوشتم، چندتا شرتکات هم براش ست کنید و خیلی راحت مدیریت کنید چینش پنجره هاتون رو، خوبیش اینه که با چندتا دستور ساده اینکار انجام شده و میتونید برحسب نیازتون تغییرش بدید.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import subprocess
import sys
#import os
def screenResolution():
CMD = ['xrandr']
CMD2 = ['grep', '\*']
P1 = subprocess.Popen(CMD, stdout=subprocess.PIPE)
P2 = subprocess.Popen(CMD2, stdin=P1.stdout, stdout=subprocess.PIPE)
P1.stdout.close()
ResolutionString, Junk = P2.communicate()
Resolution = ResolutionString.split()[0]
Width, Height = Resolution.decode().split('x')
return int(Width), int(Height)
def getCoordiantes():
CMD = ["xdotool", "getactivewindow", "getwindowgeometry", "--shell"]
result = subprocess.Popen(CMD, stdout=subprocess.PIPE)
for line in result.stdout:
yield int(line.decode().strip().split('=')[-1])
def moveWindow(X, Y, Width, Height):
Sw, Sh = screenResolution()
direction = sys.argv[1].lower()
print(direction)
if direction == 'top-right' or direction == 'tr' :
Xnew = Sw - Width
Ynew = 0
subprocess.call(['xdotool','getactivewindow' , 'windowmove', str(Xnew), str(Ynew)])
elif direction == 'top-left' or direction == 'tl':
Xnew = 0
Ynew = 0
subprocess.call(['xdotool','getactivewindow' , 'windowmove', str(Xnew), str(Ynew)])
elif direction == 'bottom-left' or direction == 'bl':
Xnew = 0
Ynew = Sh - Height
subprocess.call(['xdotool','getactivewindow' , 'windowmove', str(Xnew), str(Ynew)])
elif direction == 'bottom-right' or direction == 'br':
Xnew = Sw - Width
Ynew = Sh - Height
subprocess.call(['xdotool','getactivewindow' , 'windowmove', str(Xnew), str(Ynew)])
elif direction == 'center' or direction == 'cr':
Xnew = (Sw - Width)//2
Ynew = (Sh - Height)//2
subprocess.call(['xdotool','getactivewindow' , 'windowmove', str(Xnew), str(Ynew)])
elif direction == 'vertical-right' or direction == 'vr':
Xnew = Sw*2//3
Ynew = 0
subprocess.call(['xdotool','getactivewindow' , 'windowsize', '33%', '100%'])
subprocess.call(['xdotool','getactivewindow' , 'windowmove', str(Xnew), str(Ynew)])
elif direction == 'vertical-middle' or direction == 'vm':
Xnew = Sw//3
Ynew = 0
subprocess.call(['xdotool','getactivewindow' , 'windowsize', '33%', '100%'])
subprocess.call(['xdotool','getactivewindow' , 'windowmove', str(Xnew), str(Ynew)])
elif direction == 'vertical-left' or direction == 'vl':
Xnew = 0
Ynew = 0
subprocess.call(['xdotool','getactivewindow' , 'windowsize', '33%', '100%'])
subprocess.call(['xdotool','getactivewindow' , 'windowmove', str(Xnew), str(Ynew)])
elif direction == 'horizontal-top' or direction == 'ht':
Xnew = 0
Ynew = 0
subprocess.call(['xdotool','getactivewindow' , 'windowsize', '100%', '33%'])
subprocess.call(['xdotool','getactivewindow' , 'windowmove', str(Xnew), str(Ynew)])
elif direction == 'horizontal-middle' or direction == 'hm':
Xnew = 0
Ynew = Sh//3
subprocess.call(['xdotool','getactivewindow' , 'windowsize', '100%', '33%'])
subprocess.call(['xdotool','getactivewindow' , 'windowmove', str(Xnew), str(Ynew)])
elif direction == 'horizontal-bottom' or direction == 'hb':
Xnew = 0
Ynew = Sh*2//3
subprocess.call(['xdotool','getactivewindow' , 'windowsize', '100%', '33%'])
subprocess.call(['xdotool','getactivewindow' , 'windowmove', str(Xnew), str(Ynew)])
else:
sys.exit('''You should Choose a Right Position like:
tr for Top-Right
tl for Top-Left
br for Bottom-Right
bl for Bottom-Left
vr for Vertical-Right
vm for Vertical-Middle
vl for Vertical-Left
ht for Horizontal-Top
hm for Horizontal-Middle
hb for Horizontal-Bottom''')
def main():
_, X, Y, Width, Height, _ = (getCoordiantes())
moveWindow(X, Y, Width, Height)
if __name__ == '__main__':
if len(sys.argv) == 2:
main()
else:
sys.exit('You should Choose an option for this script like:\ntr for Top-Right\ntl for Top-Left\nbr for Bottom-Right\nbl for Bottom-Left.')
Mahatma Gandhi - The weak can never forgive. Forgiveness is the attribute of the strong
آفلاین
سلام به همهی دوستان.
من امروز متوجه شدم که ایده ی اسکریپتی مثله fingil که دوست عزیزی مثله آقای امیرصمیمی و بر و بچه های لینوکس و من کار کردن روش چقدر میتونه مفید باشه.
متاسفانه اسکریپت آقای امیرصمیمی برای من کار نکرد.
ولی خب به من این ایده رو داد که خودم بنویسمش.
با پایتون نوشتم این اسکریپتو و خودم که فوق العاده راضیم.
شدیدا توصیه میکنم دوستانی که با پایتون مینویسن اسکریپت هاشونو از argparse استفاده کنن تا اگه منتشرش کردن بقیه هم بدونن چی به چیه.
یه حالت معمولی برای اسکریپت در نظر گرفته شده و یه حالت case insensitive که برای حالت دوم فقط کافیه از اسکریپت با فلگ i استفاده کنید.
خودش تشخیص میده که میخواید از انگلیسی به فارسی تبدیل کنید یا بالعکس.
سرچ های زیادی کردم و به این نتیجه رسیدم که بهترین کار استفاده از xsel توی پایتونه و اینکه متنی که میخواد تبدیل بشه رو حتما کپی کنید، انتخاب متن به تنهایی زیاد جالب جواب نمیداد.
#!/usr/bin/env python3.5
# -*- coding: utf-8 -*-
"""
Created on Fri Mar 10 17:17:49 2017
@author: ehsun
"""
import subprocess
import argparse
import sys
import os
englishLetters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~', '"', ' ']
persianLetters = ['ش', 'ذ', 'ز', 'ی', 'ث', 'ب', 'ل', 'ا', 'ه', 'ت', 'ن', 'م', 'پ', 'د', 'خ', 'ح', 'ض', 'ق', 'س', 'ف', 'ع', 'ر', 'ص', 'ط', 'غ', 'ظ', 'ؤ', '\u200c', 'ژ', 'ي', 'ٍ', 'إ', 'أ', 'آ', 'ّ', 'ة', '»', '«', 'ء', 'ٔ', ']', '[', 'ْ', 'ً', 'ئ', 'ُ', 'َ', 'ٰ', 'ٌ', 'ٓ', 'ِ', 'ك', '۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹', '!', '"', '#', '$', '%', '،', 'گ', '(', ')', '*', '+', 'و', '-', '.', '/', ':', 'ک', '>', '=', '<', '؟', '٬', 'ج', '\\', 'چ', '×', 'ـ', '\u200d', '}', '|', '{', '÷', '؛', ' ']
length = len(persianLetters)
IgnoreCase = False
isMixture = False
def paste(src, p=True, c=True):
if p:
p = subprocess.Popen(['xsel', '-pi'], stdin=subprocess.PIPE)
p.communicate(input=src)
if c:
p = subprocess.Popen(['xsel', '-bi'], stdin=subprocess.PIPE)
p.communicate(input=src)
def isEnglish(src):
return all(ord(c) < 128 for c in src)
def english2Persian(src):
if IgnoreCase:
output = src.lower()
else:
output = src
for i in range(length):
target = englishLetters[i]
if output.find(target) == -1 :
continue
output = output.replace(target, persianLetters[i])
paste(output.encode())
def persian2English(src):
output = src
for i in range(length):
target = persianLetters[i]
if output.find(target) == -1 :
continue
output = output.replace(target, englishLetters[i])
paste(output.encode())
def mixtureTranslate(src):
srcLength = len(src)
engDict = dict([(a,b) for a,b in enumerate(src) if ord(b) < 128])
perDict = dict((i,src[i]) for i in range(srcLength) if i not in engDict)
output = [' ']*srcLength
for k,v in engDict.items():
whichLetter = englishLetters.index(v)
output[k] = persianLetters[whichLetter]
for k,v in perDict.items():
whichLetter = persianLetters.index(v)
output[k] = englishLetters[whichLetter]
result = ''.join(output)
paste(result.encode())
def translate(src):
if isMixture :
mixtureTranslate(src)
else:
if isEnglish(src):
english2Persian(src)
else:
persian2English(src)
def getSelection():
selection = subprocess.check_output(["xsel", "-b"], universal_newlines = True).strip()
isEmpty = len(selection)
if isEmpty == 0:
return
else:
translate(selection)
def checkXselExistance():
try:
subprocess.call("xsel")
except OSError as e:
if e.errno == os.errno.ENOENT:
# handle file not found error.
sys.exit("xsel binary is not founded.")
else:
# Something else went wrong while trying to run `wget`
sys.exit("There's something wrong while trying to access xsel.")
def main():
global IgnoreCase
global isMixture
parser = argparse.ArgumentParser(description = '''This script will translate you'r mistyped string
from persian to english and vice versa.''',
epilog = 'Author: Ehsan Faalpoor <faalpoor.ehsan@gmail.com> <+98 903 348 66 02>', formatter_class = argparse.RawTextHelpFormatter)
parser.add_argument('-i', '--ignoreCase', help = 'case-insensitive mode while converting from english to persian.', action = 'store_true', default = False)
parser.add_argument('-m', '--mix', help = 'use this flag when you\'r input is a mixture of persian and english letters. it\'ll figure it out how to deal with it :)', action = 'store_true', default = False)
args = parser.parse_args()
checkXselExistance()
IgnoreCase = args.ignoreCase
isMixture = args.mix
getSelection()
if __name__ == '__main__':
main()
و یه هلپ کوچولو که خود اسکریپت بهتون میده:
➜ ~ fingil -h
usage: fingil [-h] [-i] [-m]
This script will translate you'r mistyped string
from persian to english and vice versa.
optional arguments:
-h, --help show this help message and exit
-i, --ignoreCase case-insensitive mode while converting from english to persian.
-m, --mix use this flag when you'r input is a mixture of persian and english letters. it'll figure it out how to deal with it :)
Author: Ehsan Faalpoor <faalpoor.ehsan@gmail.com> <+98 903 348 66 02>
یه اپدیت کوچولو برای این اسکریپت نوشتم که الان اگه نوشتههاتون میکس هم باشند توسط این اسکریپت هندل میشن، مثه زمانی که میخواید یه متنی بنویسید که یکمش فارسی و یکمش انگلیسیه. برای این حالت فلگ m- رو گذاشتم و تک به تک کاراکتر ها چک میشن توی این حالت و به معادل خودشون توی اون یکی زبون نگاشت میشن.
به نظر خودم که چیز باحالی از آب دراومد
آخرین ویرایش توسط ehsan_faal (2017-03-14 11:51:50)
Mahatma Gandhi - The weak can never forgive. Forgiveness is the attribute of the strong
آفلاین
مخصوص window manager standalone ها. اسکریپت و راه حل برای کنترل نور صفحه کلید لپتاپ:
دایرکتوری زیر حاوی فایل هایی realtime هستش که با تغییرشون LED های دستگاه کنترل میشن.
/sys/class/leds
که در مورد من این فایل مربوط به نور کیبورد بود:
/sys/class/leds/asus::kbd_backlight
میشه با دستور زیر نور کیبورد رو عوض کرد، بین اعداد ۰ ۱ ۲ ۳ مشخصا ۰ برای خاموش و ۱ ۲ ۳ هم برای سطوح نور، واضحه که هم دایرکتوری هم فایل و هم سطوح نور تفاوت هایی داره در دستگاه های دیگه.
# echo 1 > /sys/class/leds/asus::kbd_backlight
همونطور که دیدید دسترسی روت لازمه.
اومدم و اسکریپت زیر رو نوشتم که بین این حالات سویچ بشه کرد:
/bin/kbled
--------------------------------
#!/bin/bash
action=$1
value=`cat /sys/class/leds/asus::kbd_backlight/brightness`
if [ "$action" == "increase" ]
then
if [ "$value" -lt "3" ]
then
value=$((value+1))
echo "$value" > /sys/class/leds/asus::kbd_backlight/brightness
fi
fi
if [ "$action" == "decrease" ]
then
if [ "$value" -gt "0" ]
then
value=$((value-1))
echo "$value" > /sys/class/leds/asus::kbd_backlight/brightness
fi
fi
ولی مشکل این بود که با دسترسی روت باید اجرا میشد. پس دسترسی اجرا بهش دادم، SUID رو برای فایل ست کردم و صاحب فایل رو به روت تغییر دادم:
chmod 755 /bin/kbled
sudo chmod +s /bin/kbled
sudo chown root /bin/kbled
سپس اجازه ی اجرای بدون پسورد رو به visudo دادم:
mazhar ALL=(root) NOPASSWD: /bin/kbled
و در نهایت key binding رو ست کردم برای sxhkd (برای مدیر پنجره ی bspwm):
XF86KbdBrightnessUp
sudo kbled increase
XF86KbdBrightnessDown
sudo kbled decrease
الان همه چی خوبه، شاد و خوشحال
آخرین ویرایش توسط mazhar (2017-04-14 14:45:19)
آفلاین
یکی از دوستان از من خواست تا دوتا فایل
>> MT2DInvMatlab Field Data Ver 1.0
>> Mode
1
>> Start
0
>> Spacing
2000
>> No. of Station and No. of Frequencies
10 9
>> Station
1 0.000
2 2000.000
3 4000.000
4 6000.000
5 8000.000
6 10000.000
7 12000.000
8 14000.000
9 16000.000
10 18000.000
>> Frequency
0.100000
0.220000
0.500000
1.000000
2.200000
5.000000
10.000000
22.000000
50.000000
>> Station : 1
1 0.10000 21.79487 34.33225
1 0.22000 17.05349 34.10428
1 0.50000 12.98381 37.39846
1 1.00000 11.16629 44.48720
1 2.20000 12.13725 55.62934
1 5.00000 18.11061 63.92218
1 10.00000 27.87654 65.04429
1 22.00000 42.39167 61.05557
1 50.00000 55.65763 53.33481
>> Station : 2
1 0.10000 22.43742 34.84464
1 0.22000 17.79350 34.73261
1 0.50000 13.75051 37.99397
1 1.00000 11.90243 44.87867
1 2.20000 12.87801 56.13454
1 5.00000 19.29749 65.14450
1 10.00000 30.16396 67.23283
1 22.00000 47.82108 64.91975
1 50.00000 69.13747 59.32793
>> Station : 3
1 0.10000 20.61118 35.51588
1 0.22000 16.58485 35.68085
1 0.50000 13.16295 38.93852
1 1.00000 11.60306 45.45758
1 2.20000 12.54079 56.21914
1 5.00000 18.66878 65.31519
1 10.00000 29.31100 67.57047
1 22.00000 46.85733 65.39873
1 50.00000 68.74490 59.82009
>> Station : 4
1 0.10000 19.86236 36.57528
1 0.22000 16.37782 37.12924
1 0.50000 13.53379 40.58340
1 1.00000 12.44195 46.54874
1 2.20000 13.72773 55.62804
1 5.00000 19.78740 62.92752
1 10.00000 29.72376 63.86873
1 22.00000 43.87070 59.80247
1 50.00000 55.90250 52.64983
>> Station : 5
1 0.10000 27.71699 35.58730
1 0.22000 22.61876 35.33325
1 0.50000 18.21677 37.16033
1 1.00000 15.88680 40.90506
1 2.20000 15.49888 46.84536
1 5.00000 18.26844 51.37819
1 10.00000 22.53422 50.58606
1 22.00000 25.85369 44.22736
1 50.00000 23.09800 35.27442
>> Station : 6
1 0.10000 142.14607 33.17247
1 0.22000 112.19859 31.14622
1 0.50000 84.14822 29.77993
1 1.00000 64.92179 29.53044
1 2.20000 48.80088 30.33398
1 5.00000 37.83066 31.78845
1 10.00000 31.62653 32.54084
1 22.00000 25.88997 32.24229
1 50.00000 20.33389 31.38240
>> Station : 7
1 0.10000 22.24592 35.00538
1 0.22000 18.14544 33.79557
1 0.50000 14.28390 33.52667
1 1.00000 11.58028 34.60199
1 2.20000 9.30215 38.05793
1 5.00000 8.10180 45.20340
1 10.00000 8.54867 53.66878
1 22.00000 11.63679 61.59008
1 50.00000 17.74376 64.43076
>> Station : 8
1 0.10000 26.03476 34.71297
1 0.22000 21.20366 33.01891
1 0.50000 16.42965 31.85067
1 1.00000 12.82990 32.00056
1 2.20000 9.54233 35.03463
1 5.00000 7.72613 43.65329
1 10.00000 8.20950 53.69534
1 22.00000 11.46788 61.64813
1 50.00000 17.43245 64.26675
>> Station : 9
1 0.10000 27.59122 34.60176
1 0.22000 22.45026 32.59387
1 0.50000 17.17467 30.96716
1 1.00000 13.09332 30.86868
1 2.20000 9.43998 34.29913
1 5.00000 7.64502 43.73145
1 10.00000 8.21765 53.76334
1 22.00000 11.46798 61.64218
1 50.00000 17.43256 64.26660
>> Station : 10
1 0.10000 28.35515 34.51827
1 0.22000 23.03008 32.29088
1 0.50000 17.43072 30.43257
1 1.00000 13.09094 30.37203
1 2.20000 9.36452 34.20235
1 5.00000 7.64319 43.79384
1 10.00000 8.21873 53.76084
1 22.00000 11.46695 61.64446
1 50.00000 17.43160 64.26715
به نام TM.txt و
>> MT2DInvMatlab Field Data Ver 1.0
>> Mode
2
>> Start
0
>> Spacing
2000
>> No. of Station and No. of Frequencies
10 9
>> Station
1 0.000
2 2000.000
3 4000.000
4 6000.000
5 8000.000
6 10000.000
7 12000.000
8 14000.000
9 16000.000
10 18000.000
>> Frequency
0.100000
0.220000
0.500000
1.000000
2.200000
5.000000
10.000000
22.000000
50.000000
>> Station : 1
2 0.10000 23.06108 32.50586
2 0.22000 17.25455 32.48430
2 0.50000 12.76815 36.79055
2 1.00000 11.09570 44.54148
2 2.20000 12.16827 55.55341
2 5.00000 18.08813 63.79665
2 10.00000 27.78521 64.91906
2 22.00000 42.12019 60.94293
2 50.00000 55.16396 53.32883
>> Station : 2
2 0.10000 23.44767 32.67186
2 0.22000 17.59568 32.50755
2 0.50000 12.92397 36.72028
2 1.00000 11.15682 44.84279
2 2.20000 12.36352 56.33622
2 5.00000 18.53983 65.17543
2 10.00000 28.96078 67.31739
2 22.00000 45.97089 65.11179
2 50.00000 66.82183 59.68337
>> Station : 3
2 0.10000 23.86117 32.88004
2 0.22000 18.02126 32.49082
2 0.50000 13.15533 36.23721
2 1.00000 11.11919 44.35255
2 2.20000 12.29046 56.45813
2 5.00000 18.60537 65.29459
2 10.00000 29.08015 67.45780
2 22.00000 46.34647 65.31946
2 50.00000 67.85448 59.85268
>> Station : 4
2 0.10000 24.45097 33.22821
2 0.22000 18.71699 32.58839
2 0.50000 13.75261 35.41238
2 1.00000 11.29798 42.41121
2 2.20000 11.75841 54.53436
2 5.00000 17.68463 63.61926
2 10.00000 27.19163 64.53036
2 22.00000 40.65486 60.60585
2 50.00000 52.87427 53.47828
>> Station : 5
2 0.10000 26.53474 34.77599
2 0.22000 21.18421 34.18448
2 0.50000 16.48180 36.08937
2 1.00000 14.01137 40.54419
2 2.20000 13.69286 47.91671
2 5.00000 17.00385 53.57415
2 10.00000 22.24514 52.48889
2 22.00000 26.16874 44.85861
2 50.00000 23.18503 35.35011
>> Station : 6
2 0.10000 32.58905 38.68493
2 0.22000 28.42556 38.59770
2 0.50000 24.76598 40.02197
2 1.00000 22.98546 42.39282
2 2.20000 22.96659 45.30991
2 5.00000 25.01142 46.25067
2 10.00000 26.72180 43.93707
2 22.00000 25.78950 39.03154
2 50.00000 21.59947 34.03089
>> Station : 7
2 0.10000 28.61165 35.14853
2 0.22000 23.56833 33.16859
2 0.50000 18.39450 31.40530
2 1.00000 14.25344 30.59139
2 2.20000 10.09009 32.39253
2 5.00000 7.43560 41.54270
2 10.00000 7.84407 53.64909
2 22.00000 11.32883 61.55709
2 50.00000 17.09837 63.89302
>> Station : 8
2 0.10000 28.84475 34.92510
2 0.22000 23.65465 32.54203
2 0.50000 18.01272 30.28416
2 1.00000 13.41498 29.72761
2 2.20000 9.31782 33.47351
2 5.00000 7.57129 43.78342
2 10.00000 8.20504 53.64629
2 22.00000 11.40143 61.44038
2 50.00000 17.26642 63.99197
>> Station : 9
2 0.10000 29.03618 34.81423
2 0.22000 23.71245 32.19830
2 0.50000 17.77688 29.87437
2 1.00000 13.09040 29.76910
2 2.20000 9.27918 34.10600
2 5.00000 7.63910 43.73713
2 10.00000 8.19637 53.61448
2 22.00000 11.40294 61.44359
2 50.00000 17.26760 63.99197
>> Station : 10
2 0.10000 29.18878 34.70253
2 0.22000 23.71305 31.98726
2 0.50000 17.61710 29.74267
2 1.00000 12.97684 29.95225
2 2.20000 9.31988 34.24916
2 5.00000 7.64002 43.70014
2 10.00000 8.19628 53.61847
2 22.00000 11.40331 61.44414
2 50.00000 17.26831 63.99212
به نام TE.txt رُ در فایلی به نام join.txt ذخیره و صورت
>> MT2DInvMatlab Field Data Ver 1.0
>> Mode
1
>> Start
0
>> Spacing
2000
>> No. of Station and No. of Frequencies
10 9
>> Station
1 0.000
2 2000.000
3 4000.000
4 6000.000
5 8000.000
6 10000.000
7 12000.000
8 14000.000
9 16000.000
10 18000.000
>> Frequency
0.100000
0.220000
0.500000
1.000000
2.200000
5.000000
10.000000
22.000000
50.000000
>> Station: 1
1 0.10000 21.79487 34.33225
1 0.22000 17.05349 34.10428
1 0.50000 12.98381 37.39846
1 1.00000 11.16629 44.48720
1 2.20000 12.13725 55.62934
1 5.00000 18.11061 63.92218
1 10.00000 27.87654 65.04429
1 22.00000 42.39167 61.05557
1 50.00000 55.65763 53.33481
2 0.10000 23.06108 32.50586
2 0.22000 17.25455 32.48430
2 0.50000 12.76815 36.79055
2 1.00000 11.09570 44.54148
2 2.20000 12.16827 55.55341
2 5.00000 18.08813 63.79665
2 10.00000 27.78521 64.91906
2 22.00000 42.12019 60.94293
2 50.00000 55.16396 53.32883
>> Station: 2
1 0.10000 22.43742 34.84464
1 0.22000 17.79350 34.73261
1 0.50000 13.75051 37.99397
1 1.00000 11.90243 44.87867
1 2.20000 12.87801 56.13454
1 5.00000 19.29749 65.14450
1 10.00000 30.16396 67.23283
1 22.00000 47.82108 64.91975
1 50.00000 69.13747 59.32793
2 0.10000 23.44767 32.67186
2 0.22000 17.59568 32.50755
2 0.50000 12.92397 36.72028
2 1.00000 11.15682 44.84279
2 2.20000 12.36352 56.33622
2 5.00000 18.53983 65.17543
2 10.00000 28.96078 67.31739
2 22.00000 45.97089 65.11179
2 50.00000 66.82183 59.68337
>> Station: 3
1 0.10000 20.61118 35.51588
1 0.22000 16.58485 35.68085
1 0.50000 13.16295 38.93852
1 1.00000 11.60306 45.45758
1 2.20000 12.54079 56.21914
1 5.00000 18.66878 65.31519
1 10.00000 29.31100 67.57047
1 22.00000 46.85733 65.39873
1 50.00000 68.74490 59.82009
2 0.10000 23.86117 32.88004
2 0.22000 18.02126 32.49082
2 0.50000 13.15533 36.23721
2 1.00000 11.11919 44.35255
2 2.20000 12.29046 56.45813
2 5.00000 18.60537 65.29459
2 10.00000 29.08015 67.45780
2 22.00000 46.34647 65.31946
2 50.00000 67.85448 59.85268
>> Station: 4
1 0.10000 19.86236 36.57528
1 0.22000 16.37782 37.12924
1 0.50000 13.53379 40.58340
1 1.00000 12.44195 46.54874
1 2.20000 13.72773 55.62804
1 5.00000 19.78740 62.92752
1 10.00000 29.72376 63.86873
1 22.00000 43.87070 59.80247
1 50.00000 55.90250 52.64983
2 0.10000 24.45097 33.22821
2 0.22000 18.71699 32.58839
2 0.50000 13.75261 35.41238
2 1.00000 11.29798 42.41121
2 2.20000 11.75841 54.53436
2 5.00000 17.68463 63.61926
2 10.00000 27.19163 64.53036
2 22.00000 40.65486 60.60585
2 50.00000 52.87427 53.47828
>> Station: 5
1 0.10000 27.71699 35.58730
1 0.22000 22.61876 35.33325
1 0.50000 18.21677 37.16033
1 1.00000 15.88680 40.90506
1 2.20000 15.49888 46.84536
1 5.00000 18.26844 51.37819
1 10.00000 22.53422 50.58606
1 22.00000 25.85369 44.22736
1 50.00000 23.09800 35.27442
2 0.10000 26.53474 34.77599
2 0.22000 21.18421 34.18448
2 0.50000 16.48180 36.08937
2 1.00000 14.01137 40.54419
2 2.20000 13.69286 47.91671
2 5.00000 17.00385 53.57415
2 10.00000 22.24514 52.48889
2 22.00000 26.16874 44.85861
2 50.00000 23.18503 35.35011
>> Station: 6
1 0.10000 142.14607 33.17247
1 0.22000 112.19859 31.14622
1 0.50000 84.14822 29.77993
1 1.00000 64.92179 29.53044
1 2.20000 48.80088 30.33398
1 5.00000 37.83066 31.78845
1 10.00000 31.62653 32.54084
1 22.00000 25.88997 32.24229
1 50.00000 20.33389 31.38240
2 0.10000 32.58905 38.68493
2 0.22000 28.42556 38.59770
2 0.50000 24.76598 40.02197
2 1.00000 22.98546 42.39282
2 2.20000 22.96659 45.30991
2 5.00000 25.01142 46.25067
2 10.00000 26.72180 43.93707
2 22.00000 25.78950 39.03154
2 50.00000 21.59947 34.03089
>> Station: 7
1 0.10000 22.24592 35.00538
1 0.22000 18.14544 33.79557
1 0.50000 14.28390 33.52667
1 1.00000 11.58028 34.60199
1 2.20000 9.30215 38.05793
1 5.00000 8.10180 45.20340
1 10.00000 8.54867 53.66878
1 22.00000 11.63679 61.59008
1 50.00000 17.74376 64.43076
2 0.10000 28.61165 35.14853
2 0.22000 23.56833 33.16859
2 0.50000 18.39450 31.40530
2 1.00000 14.25344 30.59139
2 2.20000 10.09009 32.39253
2 5.00000 7.43560 41.54270
2 10.00000 7.84407 53.64909
2 22.00000 11.32883 61.55709
2 50.00000 17.09837 63.89302
>> Station: 8
1 0.10000 26.03476 34.71297
1 0.22000 21.20366 33.01891
1 0.50000 16.42965 31.85067
1 1.00000 12.82990 32.00056
1 2.20000 9.54233 35.03463
1 5.00000 7.72613 43.65329
1 10.00000 8.20950 53.69534
1 22.00000 11.46788 61.64813
1 50.00000 17.43245 64.26675
2 0.10000 28.84475 34.92510
2 0.22000 23.65465 32.54203
2 0.50000 18.01272 30.28416
2 1.00000 13.41498 29.72761
2 2.20000 9.31782 33.47351
2 5.00000 7.57129 43.78342
2 10.00000 8.20504 53.64629
2 22.00000 11.40143 61.44038
2 50.00000 17.26642 63.99197
>> Station: 9
1 0.10000 27.59122 34.60176
1 0.22000 22.45026 32.59387
1 0.50000 17.17467 30.96716
1 1.00000 13.09332 30.86868
1 2.20000 9.43998 34.29913
1 5.00000 7.64502 43.73145
1 10.00000 8.21765 53.76334
1 22.00000 11.46798 61.64218
1 50.00000 17.43256 64.26660
2 0.10000 29.03618 34.81423
2 0.22000 23.71245 32.19830
2 0.50000 17.77688 29.87437
2 1.00000 13.09040 29.76910
2 2.20000 9.27918 34.10600
2 5.00000 7.63910 43.73713
2 10.00000 8.19637 53.61448
2 22.00000 11.40294 61.44359
2 50.00000 17.26760 63.99197
>> Station: 10
1 0.10000 28.35515 34.51827
1 0.22000 23.03008 32.29088
1 0.50000 17.43072 30.43257
1 1.00000 13.09094 30.37203
1 2.20000 9.36452 34.20235
1 5.00000 7.64319 43.79384
1 10.00000 8.21873 53.76084
1 22.00000 11.46695 61.64446
1 50.00000 17.43160 64.26715
2 0.10000 29.18878 34.70253
2 0.22000 23.71305 31.98726
2 0.50000 17.61710 29.74267
2 1.00000 12.97684 29.95225
2 2.20000 9.31988 34.24916
2 5.00000 7.64002 43.70014
2 10.00000 8.19628 53.61847
2 22.00000 11.40331 61.44414
2 50.00000 17.26831 63.99212
تبدیل کنم. سِد به راحتی واردِ عمل می شود:D :
touch join.txt
sed -e '/>> Station : 1/,$d' TM.txt >> ./join.txt
for i in {1..10}; do
echo ">> Station: $i" >> ./join.txt
sed -e "1,/ >> Station : $i/d" -e '/>/,$d' TM.txt >> ./join.txt
sed -e "1,/ >> Station : $i/d" -e '/>/,$d' TE.txt >> ./join.txt
done
آخرین ویرایش توسط Arcush (2017-08-15 02:41:14)
آفلاین
سلام دوستان
من به صورت اتفاقی به این تاپیک برخورد کردم و قبلا ندیده بودم دیدم همه دوستان اسکریپت های جالبی رو قرار داده بودند گفتم من هم یک اسکریپت که نوشتم رو قرار بدم
من زیاد فیلم دانلود میکنم و معمولا همه رو در مسیر پیشفرض دانلود قرار میدم که بعدا بیام فیلم هارو پوشه بندی کنم اما اگه تعداد فیلم ها زیاد بشه پوشه بندی کردن فیلم ها کار زمانگیری میشه برای همین یک اسکریپت نوشتم که این کارو رو برام انجام بده
تو این اسکریپت اسم فایل ها برداشته میشه نقطه ها از داخلش حذف میشه و به جای نقطه فاصه قرار میگیره و یک پوشه براش ساخته میشه و فیلم رو به داخل پوشه انتقال میده
فقط اسکریپت رو در جایی که نیاز دارید اجرا کنید تا کارا رو خودش انجام بده این اسکریپت روی شناسایی فایل های mkv قرار داره اگه نوع فایل شما متفاوته داخل اسکریپت به جای فرمت mkv فرمت دلخواه خودتون رو قرار بدید
#!/bin/bash
IFS=$'\n'
clear
files=`ls *mkv`
for i in $files; do
folders=$( echo "$i" | tr '.' ' ' )
echo "$folders"
mkdir -p "$folders"
mv "$i" "$folders"
done
آفلاین
سایتهایی که روی فناوریِ تولید خودکار زیرنویس از طریق شناسایی صوت کار میکنن، معمولا کارشونو دقیق انجام میدن.مثل یوتیوب، pluralsight و ...
مخصوصا من که یجورایی بنده ی حلقه بگوشِ plural شدم و زیرنویسهاشونو همیشه همراه ویدیوها میذارم تا مطالب رو بهتر درک کنم.اما مشکلی که هست، نمایشِ تعداد رقمهای بالای اعشار در برخی از زیرنویس هاست که گاها توسط پلیرها پشتیبانی نمیشه و زیرنویس عملا نشون داده نمیشه.مثلا به بخشی از زیرنویسهای تولیدشده دقت کنید:
1
00:00:02,7752334 --> 00:00:10,7752334
Now here we have the API that we just built. It's /api/books, it returns back a list of books that we have
2
00:00:10,7752334 --> 00:00:17,7752334
in our MongoDB database and you've seen me do this over the course of this entire course, when I want an
اون تعداد رقم های بالای اعشار عملا باعث میشه زیرنویس نشون داده نشه.(احتمالا مشکل از پلیرهاست یا شاید تنظیماتی وجود داشته باشه که بشه بدون کدنویسی این مشکلو حل کرد.خبرم کنید اگه راه سادهتری برای حل این مشکل وجود داره.)
در هر صورت دست به کار شدم و با پایتون تکه کد زیر رو نوشتم و اسمشو گذاشتم subdigitfixer:
#!/usr/bin/python
"""Re-Format Bad Subtitle Digits.
For Example Convert:
00:00:01,2419001 --> 00:00:09,2419001 to 00:00:01,24 --> 00:00:09,24
Usage:
python3 subdigitfixer.py </pat/to/file>
"""
import re
import sys
def readSubtitle(file):
"""Read A Bad Subtitle That have Some Digit Issues.
Args:
file: The PATH of The Input File.
"""
lines = []
pattern = re.compile("-->")
with open(file) as infile:
for i, line in enumerate(infile):
for match in re.finditer(pattern, line):
flagPartStart = False
flagPartEnd = False
startPart = match.string.split("-->")[0]
goodPartStart = startPart.split(",")[0]
if(len(startPart.split(",")) < 2):
goodPartStart = startPart
# flagPartStart = True
else:
badPartStart = startPart.split(",")[1]
if (len(badPartStart) > 2):
badPartStart = badPartStart[:2]
goodPartStart += "," + badPartStart
flagPartStart = True
endPart = match.string.split("-->")[1]
goodPartEnd = endPart.split(",")[0]
if(len(endPart.split(",")) < 2):
goodPartEnd = endPart
# flagPartEnd = True
else:
badPartEnd = endPart.split(",")[1]
if (len(badPartEnd) > 2):
badPartEnd = badPartEnd[:2]
goodPartEnd += "," + badPartEnd
flagPartEnd = True
if (flagPartStart or flagPartEnd):
newLine = goodPartStart + "-->" + goodPartEnd + "\n"
line = line.replace(line, newLine)
lines.append(line)
return lines
def writeSubtitle(file):
"""Write Lines in The Same File.
Args:
File: The PATH of The Output File.
"""
lines = readSubtitle(file)
with open(file, 'w') as outfile:
for line in lines:
outfile.write(line)
def main(file):
"""Re-Format Bad Subtitle Digits.
Args:
File: The PATH of The Input File.
"""
writeSubtitle(file)
if __name__ == '__main__':
main(sys.argv[1]) # The 0th arg is the module filename
دیگه فرصت نشد براش پکیج بسازم. واسه اینکه کارتون راحت بشه اول اجرایی ش کنید و بعد مسیرشو به متغیر PATH سیستم تون(.zshrc) اضافه کنید:
export PATH=$PATH:"/home/saeed/lib"
بعد:
subShaper /path/to/subShaper/subtitle.srt
و خروجی پس از اجرا که دو رقم آخر رو نگه داشته:
0:00:02,77--> 00:00:10,77
Now here we have the API that we just built. It's /api/books, it returns back a list of books that we have
2
00:00:10,77--> 00:00:17,77
in our MongoDB database and you've seen me do this over the course of this entire course,
آخرین ویرایش توسط LinArcX (2017-10-21 23:00:32)
آفلاین
سلام به همگی
چند وقت پیش برای یک نیاز یکی از دوستان یه اسکریپت نوشتم که نیاز های زیر را برطرف میکنه.
− سوزاندن زیرنویس روی ویدیو
− افزودن لوگو روی ویدیو ( به صورت پیشفرض لوگو را بالا سمت چپ اضافه میکنه )
− افزودن Intro به ویدیو ( البته باید هر دو ویدیو از نظر ابعاد تصویر برابر باشند)
− تبدیل زیرنویس srt به ass و افزودن استایل به آن
****** این اسکریپت از نظر محل نمایش زیرنویس طوری بهینه شده که زیرنویس تداخلی با آدرس کانال که سایت اپارات روی ویدیوها ( پایین سمت چپ ویدیو) اضافه میکند نداشته باشد. ******
اما اسکریپت:
#!/bin/bash
video="$1"
subtitle="$2"
logo="$3"
videoname=$(echo "$1" | rev | cut -f2 -d '.' | rev)
subtitlename=$(echo "$2" | rev | cut -f2 -d '.' | rev | sed -e 's/ /_/g')
ffmpeg -i "$2" ".sample999.ass"
sed -i "9 d" ".sample999.ass"
sed -i "9i Style: Default,ubvazir,20,&H0000FFFF,&H000000FF,&H71000000,&HFF000000,0,0,0,0,100,100,0,0,1,0,0,2,10,10,20,178" ".sample999.ass"
ffpb -i "$1" -i "$3" -filter_complex "[0]subtitles=.sample999.ass:force_style='OutlineColour=&H80000000,BorderStyle=3,Outline=0.1, Shadow=0,MarginV=20'[0v];[0v][1:v]overlay=W-w-10:10" -c:v libx264 -c:a libmp3lame -ar 48000 "$videoname-Hs".mkv
rm .sample999.ass
mkvmerge -o "$videoname-Intro".mkv intro.mkv + "$videoname-Hs".mkv
rm "$videoname-Hs".mkv
clear
طریقه استفاده از زیرنویس
./hardsub video.mp4 subtitle.srt logo.png
خروجی زیرنویس یک فایل mkv خواهد بود. این اسکریپت یک سری پیشنیاز لازم داره تا کار کنه
− mkvmerge
- ffmpeg
- ffpb ( یه پروگرس بار هست برای ffmpeg )
− فونت ubvazir
در پایان لازم به ذکر است که بنده نه برنامه نویس هستم و نه تا حالا اسکریپت نوشته بودم لذا این اسکریپت قطعا اشکالات نگارشی و فنی دارد.
آخرین ویرایش توسط بهروز رمضانی (2018-07-02 20:36:58)
در یادگیری و استفاده از خط فرمان کوشا باشید چرا که رستگاری شما در آن است.
آفلاین
خب من از PhpStorm استفاده میکنم و معتقدم یکی از بهترین ide ها برای توسعه وب هست اما متاسفانه انحصاری و تجاری هست ؛ خیلی ها مثل من نمیتونن license این برنامه رو بخرن یا این که دوست ندارن کرکش کنن و اینجور چیز ها ؛ خب خلاصه این که یه راه حل میمونه اونم استفاده از evaluator license سی روزه خود PhpStorm هست که محدودیتش مشخصه؛ اما میتونیم از این لایسنس به صورت نامحدود به کمک اسکریپت زیر استفاده کنیم(برای سایر ابزار های این کمپانی هم استفاده داره کافیه چک کنید):
#!/bin/bash
## declare array of tools
tools="PhpStorm"
for tool in "${tools[@]}"
do
echo "removing evaluation key for $tool"
rm -rf ~/.$tool*/config/eval
rm -rf ~/.java/.userPrefs/jetbrains/${tool,,}
done
for tool in "${tools[@]}"
do
echo "resetting evalsprt in options.xml for $tool"
sed -i '/evlsprt/d' ~/.$tool*/config/options/options.xml
done
echo "resetting evalsprt in prefs.xml"
sed -i '/evlsprt/d' ~/.java/.userPrefs/prefs.xml
for tool in "${tools[@]}"
do
echo "change date file for $tool"
find ~/.$tool* -type d -exec touch -t $(date +"%Y%m%d%H%M") {} +;
find ~/.$tool* -type f -exec touch -t $(date +"%Y%m%d%H%M") {} +;
done
خب خیلی چیزا تو زندگی آدما گذرا هستن؛ خصوصا علاقیات! بعضی آدما هم متفاوتن و به علاقه هاشون به هر قیمتی میچسبن. گنو/لینوکس چیزی بود که در من ریشه پیدا کرد.
صفحه گیت هاب من.
ايميل من
آفلاین