Oil ends lower for second week as stockpiles rise, demand weakens