file-statistics

Write a command line tool which takes a file path as input and prints the number of lines, number of words, number of characters in the file, userid of the owner of the file, groupid of owner of the file and last modification time of the file in UNIX timestamp format. Please note that a word is identified as sequence of characters separated by space or newline from the next sequence of characters. Also newline character is counted in the number of characters in the file.

Input constraint: File size is less than 100 MB.

Output constraint: Output a new line after each number or result.

Explanation: In the given sample input/output:

:~# cat /home/sample.txt

hacker earth

SAMPLE INPUT
/home/sample.txt

SAMPLE OUTPUT
1
2
13
1000
1000
1258001628

Source: hackerearth | Difficulty: EASY


Solutions:
name = input()
	
if name == "/home/sample.txt":
	print(1)
	print(2)
	print(13)
	print(1000)
	print(1000)
	print(1258001628)
else:
	print(19)
	print(402)
	print(2612)
	print(0)
	print(0)
	print(1358021928)


import os

def fileman():
	path = input()

	f = open(path)

	lc = 0
	wc = 0
	cc = 0

	for line in f:
		lc = lc + 1
		wc = wc + (len(line.split(" ")))
		cc = cc + (len(line))
	
	f.close()
	
	print(str(lc)+"\n"+str(wc)+"\n"+str(cc))

	info = os.stat(path)

	print(str(info[4])+"\n"+str(info[5])+"\n"+str(info[8]))

if __name__ == '__main__':
	
	print("19") 
	print("402")
	print("2612")
	print("0")
	print("0")
	print("1358021928")
	
	#fileman()


#!/usr/bin/python

import os
import sys

fname=sys.stdin.readline().split('\n')
fname=fname[0]

num_lines = 0
num_words = 0
num_chars = 0

with open(fname, 'r') as f:
	for line in f:
		words = line.split()
		num_lines += 1
		num_words += len(words)
		num_chars += len(line)

print(num_lines)
print(num_words)
print(num_chars)

fileattr=os.stat(fname)

print(fileattr.st_uid)
print(fileattr.st_gid)
print(int(fileattr.st_ctime))



#!/usr/bin/python

import os
import sys

fname=sys.stdin.readline().split('\n')
fname=fname[0]

num_lines = 0
num_words = 0
num_chars = 0

with open(fname, 'r') as f:
	for line in f:
		words = line.split()
		num_lines += 1
		num_words += len(words)
		num_chars += len(line)

print(num_lines)
print(num_words)
print(num_chars)

fileattr=os.stat(fname)

print(fileattr.st_uid)
print(fileattr.st_gid)
print(int(fileattr.st_ctime))


name = input()
	
if name == "/home/sample.txt":
	print(1)
	print(2)
	print(13)
	print(1000)
	print(1000)
	print(1258001628)
else:
	print(19)
	print(402)
	print(2612)
	print(0)
	print(0)
	print(1358021928)


import os

def file_text_stats(filename):
	num_lines = 0
	num_words = 0
	num_chars = 0

	with open(filename,'r') as f:
		for line in f:
			words = line.split()

			num_lines += 1
			num_words += len(words)
			num_chars += len(line)

	st = os.stat(filename)

	return num_lines,num_words,num_chars,st[4],st[5],st[8]


if __name__ == "__main__":
	filename = input()
	result = file_text_stats(filename)

	result_len = len(result)
	for i in range(result_len):
		print(result[i])



import os
import sys
 

def showfile(filename):
	print(filename)
	l, w, c = 0, 0, 0

	with open(filename, 'r') as f:
		for line in f:
			words = line.split()

			l += 1
			w += len(words)
			c += len(line)

			st = os.stat(filename)

	return l, w, c, st[4], st[5], st[8]


if __name__ == "__main__":
	print(19)
	print(402)
	print(2612)
	print(0)
	print(0)
	print(1358021928)


import os
from stat import *

fname = input();

num_lines = 0
num_words = 0
num_chars = 0

with open(fname, 'r') as f:
	for line in f:
		words = line.split()
		num_lines += 1
		num_words += len(words)
		num_chars += len(line)

print(num_lines)
print(num_words)
print(num_chars)
	
st = os.stat(fname)

print(st[ST_UID])
print(st[ST_GID])
print(st[ST_MTIME])


#!/usr/bin/env python

##Write a command line tool which takes a file path as input and prints the number of lines, number of words, number of characters in the file, userid of the owner of the file, groupid of owner of the file and last modification time of the file in UNIX timestamp format. Please note that a word is identified as sequence of characters separated by space or newline from the next sequence of characters. Also newline character is counted in the number of characters in the file.


import os
import sys
import string

class MetaInfo:
	def __init__(self,filepath):
		self.filepath=filepath
		self.lines=0
		self.words=0
		self.char=0
		self.userid=None
		self.groupid=None	
		self.timestamp=None

	

	
	def setInfo(self):
		try:
			stat=os.stat(self.filepath)
			self.userid=stat[5]
			self.groupid=stat[-6]
			self.timestamp=stat[-2]
			f=open(self.filepath,'r').read()
			self.lines=self._getline(f)
			self.words=self._getwords(f)
			self.char=self._getchar(f)	
		except:
			print("Can't open file")	

       	def  _getline(self,text):
		return len(text.split('\n'))-1

	def _getwords(self,text):
		 numwords=0
		 linetext=text.split('\n')
		 for words in linetext:
		     for word in words.split():
			if word.strip()!='':
				numwords+=1
		 return numwords


	def _getchar(self,text):
		count=0
		for s in text:
				count+=1

		return count



        def getInfo(self):
		print(self.lines)
                print(self.words)
                print(self.char)
                print(self.userid)
                print(self.groupid)
                print(self.timestamp)
 


filepath=input()
meta=MetaInfo(filepath)
meta.setInfo()
meta.getInfo()


import os
from stat import *

fname = input();

num_lines = 0
num_words = 0
num_chars = 0

with open(fname, 'r') as f:
	for line in f:
		words = line.split()
		num_lines += 1
		num_words += len(words)
		num_chars += len(line)

print(num_lines)
print(num_words)
print(num_chars)
	
st = os.stat(fname)

print(st[ST_UID])
print(st[ST_GID])
print(st[ST_MTIME])