Friday, 14 September 2018

Perl to download mp3 from the html page using wget

The script I have tried to get the mp3 files from the web.

#!/usr/bin/perl

die "Usage: $0 <url of page> \n" if @ARGV < 1;

sub getLineFromFile
{
my @outArray;
my $in = shift;
open (my $inf,"<",$in) or die "can't reader the $in";
while(my $row = <$inf>)
{
chomp $row;
#print $row."\n";
push (@outArray,$row);

return @outArray;
}

my $url = shift;
`wget $url`;

$url =~ /([^\/]+\.html)/; #Regex to look for last / and token next with .html 
my$filename = $1;

my @lines = getLineFromFile($filename);

foreach my $line (@lines)
{
my $command;
$line =~/<a .*href="(.*download.*\.mp3)">/; #modify if you find any different href url
my $mp3url = $1;
if($mp3url =~ /\.mp3$/){
#print "get me ".$mp3url."\n";
`wget $mp3url`;

}
}
unlink $filename;


hope it helps and save your time 👍

Monday, 27 August 2018

Install cv2 or opencv-python module in MACos

It took a while to figure out the issues during installing the OpenCV to my mac machine.
Here are the steps that I followed to fix it. maybe it could help you too...

I have opened the Terminal and gave "pip install OpenCV-python". Here the problem starts...


$ sudo -H pip install opencv-python
Password:
Collecting opencv-python
  Downloading https://files.pythonhosted.org/packages/ae/f7/01fc83414fbdbb470d6d77ee4a0fd32234046edc4a2e4f7897e3e95ee666/opencv_python-3.4.2.17-cp27-cp27m-macosx_10_6_x86_64.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (42.2MB)
    100% |████████████████████████████████| 42.3MB 244kB/s 
Collecting numpy>=1.11.1 (from opencv-python)
  Downloading https://files.pythonhosted.org/packages/e7/c1/d5c47de35e366b1c2f60da88a24b25d3037b892417c5c3c5398313fb54f5/numpy-1.15.1-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (24.5MB)
    100% |████████████████████████████████| 24.5MB 569kB/s 
matplotlib 1.3.1 requires nose, which is not installed.
matplotlib 1.3.1 requires tornado, which is not installed.
Installing collected packages: numpy, opencv-python
  Found existing installation: numpy 1.8.0rc1
Cannot uninstall 'numpy'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
oops, here 😈 starts...
But no worries I got your back.

Here are the few steps that could solve it.

1) Install the tornado package.


$ sudo -H pip install tornado
Collecting tornado
  Downloading https://files.pythonhosted.org/packages/45/ec/f2a03a0509bcfca336bef23a3dab0d07504893af34fd13064059ba4a0503/tornado-5.1.tar.gz (516kB)
    100% |████████████████████████████████| 522kB 1.5MB/s 
Collecting futures (from tornado)
  Downloading https://files.pythonhosted.org/packages/2d/99/b2c4e9d5a30f6471e410a146232b4118e697fa3ffc06d6a65efde84debd0/futures-3.2.0-py2-none-any.whl
Collecting singledispatch (from tornado)
  Downloading https://files.pythonhosted.org/packages/c5/10/369f50bcd4621b263927b0a1519987a04383d4a98fb10438042ad410cf88/singledispatch-3.4.0.3-py2.py3-none-any.whl
Collecting backports_abc>=0.4 (from tornado)
  Downloading https://files.pythonhosted.org/packages/7d/56/6f3ac1b816d0cd8994e83d0c4e55bc64567532f7dc543378bd87f81cebc7/backports_abc-0.5-py2.py3-none-any.whl
Requirement already satisfied: six in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from singledispatch->tornado) (1.4.1)
Installing collected packages: futures, singledispatch, backports-abc, tornado
  Running setup.py install for tornado ... done
Successfully installed backports-abc-0.5 futures-3.2.0 singledispatch-3.4.0.3 tornado-5.1

2) Then install the nose package. "sudo -H pip install nose"

3) Actually, this should be the final step but as I have the older version of numpy. It has thrown a stone against 💣💣.

$sudo -H pip install opencv-python

Collecting opencv-python
  Using cached https://files.pythonhosted.org/packages/ae/f7/01fc83414fbdbb470d6d77ee4a0fd32234046edc4a2e4f7897e3e95ee666/opencv_python-3.4.2.17-cp27-cp27m-macosx_10_6_x86_64.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Collecting numpy>=1.11.1 (from opencv-python)
  Using cached https://files.pythonhosted.org/packages/e7/c1/d5c47de35e366b1c2f60da88a24b25d3037b892417c5c3c5398313fb54f5/numpy-1.15.1-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Installing collected packages: numpy, opencv-python
  Found existing installation: numpy 1.8.0rc1
Cannot uninstall 'numpy'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

4) So to solve the above issue the numpy need to be updated.

$ sudo -H pip install --ignore-installed numpy
Collecting numpy
  Downloading https://files.pythonhosted.org/packages/e7/c1/d5c47de35e366b1c2f60da88a24b25d3037b892417c5c3c5398313fb54f5/numpy-1.15.1-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (24.5MB)
    100% |████████████████████████████████| 24.5MB 642kB/s 
Installing collected packages: numpy
Successfully installed numpy-1.15.1

5) Now we are ready to install OpenCV

$ sudo -H pip install opencv-python
Collecting opencv-python
  Using cached https://files.pythonhosted.org/packages/ae/f7/01fc83414fbdbb470d6d77ee4a0fd32234046edc4a2e4f7897e3e95ee666/opencv_python-3.4.2.17-cp27-cp27m-macosx_10_6_x86_64.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Requirement already satisfied: numpy>=1.11.1 in /Library/Python/2.7/site-packages (from opencv-python) (1.15.1)
Installing collected packages: opencv-python
Successfully installed opencv-python-3.4.2.17


Hope this helps 👍 .....





Tuesday, 19 June 2018

Substring implementation in C

small code snippet of substring implementation in C, may save you time ..


 char *substring(int start, int finish, const char *inString) {

  int inlen = strlen(inString);
    char result[inlen];
    char tmp[2];
    int i,k;
    for (i=start,k=0;i<finish;i++,k++)
    {
    result[k]=inString[i];
    }
    return result;
}



Happy coding 👍😉

Thursday, 4 January 2018

Operation not permitted in MAC OS for delete and move

While trying the delete or move operation in the command prompt, we faced a issue that even root user can't delete or move or rename the folder or file.

was 👀  looking in the found a solution.

May save your time too ...

Steps to resolve:

1) open a Terminal.
2) go to the previous directory in which you face issue. IN my cases ~/Download is the folder in which i can remove any, due to Operation not permitted issue.  So I have moved to /users/xxxx
3)  run the following command in sudo.

     sudo chflags -R nouchg,nouappnd ~/Downloads/ 

replace the folder in which you are facing issue in instead of ~/Downloads/  in above command.

Hope will this helped you 👍